PERF: Text rendering speedups - #32120
scottshambaugh wants to merge 8 commits into
Conversation
|
Out of curiosity, have you seen |
b20d2fb to
e133bf0
Compare
|
@iccir yup! That showed up and is addressed (at least in this use case) by commit 7's caching. |
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! |
|
Hey @iccir, I got your review comments via email but they don't show when I click through... not sure how well comments on a commit work. But to respond:
I like that! Added a commit with those changes. Made a specific
Yeah, I don't see this showing up in profiling results at all. |
569934f to
6561fa9
Compare
iccir
left a comment
There was a problem hiding this comment.
I checked the new GlyphPtr commit as I had already checked the others when I last reviewed.
I think everything looks good; however, this is right at the edge of my Python/C++ knowledge. I won't be offended if you want a 3rd pair of eyes :)
I think that makes sense. |
| } | ||
| } | ||
| auto const& clip = text_clip_rect(gc.cliprect); | ||
| auto data = buffer.data(0); |
There was a problem hiding this comment.
I think you need to add the composite operator before this loop here after the blend group PRs pixFmt.comp_op(gc.comp_op);
There was a problem hiding this comment.
Is there an LRU cache eviction we can use instead of clearing and restarting?

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