Skip to content

Add TextPool: keyed cache of reusable Text objects#2847

Open
pvcraven wants to merge 1 commit intodevelopmentfrom
feature/text-pool
Open

Add TextPool: keyed cache of reusable Text objects#2847
pvcraven wants to merge 1 commit intodevelopmentfrom
feature/text-pool

Conversation

@pvcraven
Copy link
Copy Markdown
Member

@pvcraven pvcraven commented May 7, 2026

Summary

  • Adds TextPool class to arcade/text.py — a keyed cache of reusable Text objects that avoids the cost of creating new arcade.Text objects every frame for dynamic text (scores, labels, FPS counters, etc.)
  • draw(key, text, x, y, ...) creates on first call, efficiently updates on subsequent calls, then draws
  • get(key, text, x, y, ...) same but without drawing — useful for measuring content_width before layout
  • Pool-wide defaults (font_name, bold, anchor_x, etc.) set in constructor, overridable per-call
  • Uses Text.__enter__/__exit__ context manager for efficient batched property updates via pyglet's begin_update()/end_update()

Test plan

  • 12 unit tests covering: creation, reuse (same id()), property updates, get() vs draw(), clear(), remove(), defaults, overrides, content_width access
  • All 36 existing text tests still pass
  • from arcade import TextPool works

🤖 Generated with Claude Code

Games drawing dynamic text every frame pay a performance cost creating
arcade.Text objects repeatedly. TextPool provides a keyed cache that
creates Text objects on first use and efficiently updates them on
subsequent calls, avoiding reconstruction costs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant