PERF: Text rendering speedups - #32120
Open
scottshambaugh wants to merge 7 commits into
Open
Conversation
Contributor
|
Out of curiosity, have you seen |
scottshambaugh
force-pushed
the
text_render_perf
branch
from
July 25, 2026 19:22
b20d2fb to
e133bf0
Compare
Contributor
Author
|
@iccir yup! That showed up and is addressed (at least in this use case) by commit 7's caching. |
Contributor
Fantastic! I thought that might be the case, but I wasn't 100% sure. Thanks for letting me know, now I can stop trying to find the example that caused it! |
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.
PR summary
Inspired by #32064, I dug into text rendering to try and see what we could speed up. Through a combination of caching, lazy loading, and combining runs of glyphs into a single rasterization pass, total figure draw time on my simple demo script below is sped up by 2.4x. This is separate from (and stacks on top of) the improvements in #32064. Beyond the immediate rendering, text is also handled in figure/subplot layout, so there are speedups across the entire call tree.
This is a big diff and stacked PRs aren't available yet, so is probably easiest to review by commit. Each is self contained, and here is a table describing them:
d002b6c8b593436b4048681b265ea1shaping_state()is more complex here, as the result depends on the state of this face and of every fallback face it may shape with.0587aa44b933c40f64c9get_path().51d14736dae133bf037cText._get_layout.Before (4.03 sec draw):

After (1.86 sec draw):

Benchmark script:
AI Disclosure
Lots of help from claude on the first pass for this one. I spent several hours reviewing and polishing its draft, and am confident in each of the changes. What I am less confident on is potential corner cases of the text rendering pipeline that I'm unfamiliar with, so would appreciate @QuLogic to take a look through this when he has the time.
PR checklist