Text performance regression fix#24663
Conversation
Added `clear-font-atlases` arg to `many_text` example.
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
Out of curiosity, is this regression visible in |
Should be, yes. Anything that calls |
Trashtalk217
left a comment
There was a problem hiding this comment.
I've tested it locally and I went from 35fps to 110fps. Good job! Although I do wonder if it's possible to clean up the function a little. We're indented quite far here.
# Objective Disclaimer: AI was used to find/triage the issue, but I spent quite a bit of time verifying everything. I am not a text rendering exptert though. While investigating the performance regression fixed in bevyengine#24663 in my own project, I stumbled upon another one related to caching and font hinting. As mentioned in https://docs.rs/swash/latest/swash/struct.FontRef.html#owning-your-fonts, using the `FontRef` constructors implicitly generates new `CacheKey` instances, which breaks the internal caching layer. Using the scale builder without giving an id does this internally, which is a bit of a footgun. I believe `cosmic_text` handled this before, and that this is a regression from the move to `parley`. When running `many_text2d --hinting` the startup time went from 7s to 500ms. I couldn't get a good tracy screenshot running with `--recompute` because the fps on main is too low. Note that the measurements are based on main before bevyengine#24663. <img width="745" height="324" alt="screenshot-2026-06-22-165610" src="https://github.com/user-attachments/assets/62881ddb-84eb-4b20-b26e-8d305c3bb99a" /> <img width="634" height="527" alt="screenshot-2026-06-22-165624" src="https://github.com/user-attachments/assets/96a38ef4-d51a-4c5e-a518-2596b212e1f6" /> ## Solution Give the builder a stable font id. Someone should confirm if this is indeed a valid ID to give to swash, or if I forgot to take some feature(s) into account. I also added a `hinting` flag to `many_text2d` that I used for testing, seems useful to keep. ## Testing Ran `many_text2d`, saw better performance and that the text looked similar.
Objective
Text layout updates take much longer than in 0.18.
Solution
update_text_layout_infowas building a new SwashScalerfor every run.Instead, only build a new
Scalerwhen it is needed to rasterize new glyphs.Also added a
clearmethod toFontAtlasSets. This is used by themany_textexample with the--clear-font-atlasesarg to bench glyph rasterization.Testing
Includes a new text benchmark
many_text:On my computer on main it reports ~35fps, with this branch ~130fps.