bevy_text: give swash a stable font id#24710
Merged
Merged
Conversation
alice-i-cecile
requested changes
Jun 22, 2026
alice-i-cecile
left a comment
Member
There was a problem hiding this comment.
Okay, I've dug into the code here, and I think this fix is correct. What a nasty footgun.
However, there's another usage of this pattern that needs to be fixed, and should be done at the same time, over in
Contributor
Author
I fixed that one as well, and tested with the |
alice-i-cecile
approved these changes
Jun 22, 2026
ickshonpe
approved these changes
Jun 22, 2026
ickshonpe
left a comment
Contributor
There was a problem hiding this comment.
Yep this is correct, it's a nice improvement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 #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
FontRefconstructors implicitly generates newCacheKeyinstances, 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 believecosmic_texthandled this before, and that this is a regression from the move toparley.When running
many_text2d --hintingthe startup time went from 7s to 500ms. I couldn't get a good tracy screenshot running with--recomputebecause the fps on main is too low. Note that the measurements are based on main before #24663.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
hintingflag tomany_text2dthat I used for testing, seems useful to keep.Testing
Ran
many_text2d, saw better performance and that the text looked similar.