mirror of
https://github.com/bevyengine/bevy.git
synced 2026-06-30 07:45:50 -04:00
097fc03ce5
# 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 https://github.com/bevyengine/bevy/pull/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 #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.
Stress tests
These examples are used to stress test Bevy's performance in various ways. These should be run with the "stress-test" profile to accurately represent performance in production, otherwise they will run in cargo's default "dev" profile which is very slow.
Example Command
cargo run --profile stress-test --example <EXAMPLE>