-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Free unused font atlases #21211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Free unused font atlases #21211
Conversation
* Removed `TextFont` and `TextColor` from the `Text`, `Text2d`, and `TextSpan` requires, replaced with `ComputedTextStyle`. * `update_text_styles` updates the `ComputedTextStyle`s each frame from the text entities nearest ancestors with `TextFont` or `TextColor` components.
… for 2d and UI, resolve_2d_computed_text_styles and resolve_ui_computed_text_styles. * Added `scale_factor` field to `ComputedTextStyle`.
* Finished the `free_unused_font_atlases` system.
Is there an easier way to review a stacked PR? Having to mentally subtract out all the diffs from the previous change is a chore. |
I'm not sure, but all these other PRs are based on the |
Objective
Fixes #21210
Solution
Use a least recently used cache (suggested by @viridia). Don't free unused font atlases immediately, only once the font count is higher than the max fonts limit. Font atlases are never freed while their font is in use.
Performance Notes
For the sake of simplicity, plan to leave most of these for follow up PRs:
The LRU cache implementation isn't optimal, I just want to keep things simple for now as so many different text changes are needed.
The list of in use fonts is rebuilt every frame, this should be avoidable using some combination of change detection, observers, and reference counting. For most applications this won't be a problem though, as the numbers are relatively low.
Probably there should be a memory use limit and a hard limit to the total number of fonts.
Testing
Seems to work, except for TextSpans with Text2d.
Showcase