Skip to content

bevy_text: give swash a stable font id#24710

Merged
alice-i-cecile merged 3 commits into
bevyengine:mainfrom
kristoff3r:ks/cache-key
Jun 23, 2026
Merged

bevy_text: give swash a stable font id#24710
alice-i-cecile merged 3 commits into
bevyengine:mainfrom
kristoff3r:ks/cache-key

Conversation

@kristoff3r

@kristoff3r kristoff3r commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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 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.

screenshot-2026-06-22-165610 screenshot-2026-06-22-165624

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.

@kristoff3r kristoff3r added C-Bug An unexpected or incorrect behavior D-Complex Quite challenging from either a design or technical perspective. Ask for help! A-Text Rendering and layout for characters labels Jun 22, 2026
@kristoff3r kristoff3r requested a review from ickshonpe June 22, 2026 15:33
@kristoff3r kristoff3r added this to the 0.19.1 milestone Jun 22, 2026
@kristoff3r kristoff3r added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jun 22, 2026

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 22, 2026
@kristoff3r kristoff3r added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jun 22, 2026
@kristoff3r

Copy link
Copy Markdown
Contributor Author

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

I fixed that one as well, and tested with the text_input example.

@ickshonpe ickshonpe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this is correct, it's a nice improvement.

@ickshonpe ickshonpe added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 22, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 23, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 23, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 23, 2026
Merged via the queue into bevyengine:main with commit 097fc03 Jun 23, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Text Rendering and layout for characters C-Bug An unexpected or incorrect behavior D-Complex Quite challenging from either a design or technical perspective. Ask for help! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants