Pre-allocate some ShapedText storage - #702
Merged
Merged
Conversation
Implementing linebender#679 (comment) seems to be a nice little speed up. ``` $ cargo bench --bench main -- compare ../target/benchmarks/main -t 8. Default Style - arabic 20 characters [ 9.0 us ... 8.8 us ] -2.09%* Default Style - latin 20 characters [ 4.3 us ... 4.1 us ] -3.14%* Default Style - japanese 20 characters [ 8.3 us ... 8.3 us ] -0.33% Default Style - arabic 1 paragraph [ 48.7 us ... 47.8 us ] -1.80%* Default Style - latin 1 paragraph [ 16.8 us ... 16.5 us ] -2.07%* Default Style - japanese 1 paragraph [ 70.6 us ... 70.1 us ] -0.76% Default Style - arabic 4 paragraph [ 208.1 us ... 201.5 us ] -3.13%* Default Style - latin 4 paragraph [ 64.0 us ... 62.8 us ] -1.84%* Default Style - japanese 4 paragraph [ 99.9 us ... 98.8 us ] -1.03%* Styled - arabic 20 characters [ 10.1 us ... 9.8 us ] -2.32%* Styled - latin 20 characters [ 5.4 us ... 5.3 us ] -1.94%* Styled - japanese 20 characters [ 8.9 us ... 9.0 us ] +1.59%* Styled - arabic 1 paragraph [ 51.2 us ... 50.2 us ] -1.86%* Styled - latin 1 paragraph [ 21.4 us ... 21.1 us ] -1.11%* Styled - japanese 1 paragraph [ 77.2 us ... 76.7 us ] -0.73% Styled - arabic 4 paragraph [ 227.8 us ... 221.3 us ] -2.88%* Styled - latin 4 paragraph [ 83.2 us ... 82.3 us ] -1.09%* Styled - japanese 4 paragraph [ 109.1 us ... 108.1 us ] -0.98% ```
taj-p
approved these changes
Jul 21, 2026
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.
Implementing #679 (comment) seems to be a nice little speed up.
This pre-allocates at the granularity of items, which means the glyph allocation is speculative. An alternative is to pre-allocate at the smaller granularity of runs, once you know how many glyphs you need to push, but that turns out to be slower as you need to reallocate more often.
We could expose
ShapedText::reservepublicly and let users handle pre-allocation (at, e.g., the paragraph level), which theoretically could be slightly faster still, but that adds API surface for something that mostly stops mattering once you're reusing theShapedTextallocation.