PERF: Text handling speedups#31001
Merged
QuLogic merged 16 commits intomatplotlib:text-overhaulfrom Mar 2, 2026
Merged
Conversation
267a86f to
6a7f558
Compare
fe70db4 to
f35c71d
Compare
Contributor
Author
|
Ready for review. @anntzer FYI - you're probably the most familiar with the text sections here |
anntzer
reviewed
Jan 20, 2026
anntzer
reviewed
Jan 20, 2026
anntzer
reviewed
Jan 20, 2026
anntzer
reviewed
Jan 20, 2026
anntzer
reviewed
Jan 20, 2026
81dfd7e to
810db09
Compare
scottshambaugh
commented
Jan 20, 2026
Contributor
|
Do you want to also include the simplification(/speedup) mentioned at #31000 (review) (don't bother with cm_set() in Text.draw)? I can also make a separate PR for that if you prefer. |
c0941a2 to
4695392
Compare
Contributor
Author
|
Removed the wrapped text context manager |
anntzer
reviewed
Feb 3, 2026
anntzer
reviewed
Feb 3, 2026
c40ef34 to
55e11b4
Compare
1 task
anntzer
reviewed
Feb 7, 2026
Contributor
Author
|
Why do rebases always go wrong... should be fixed now. |
anntzer
approved these changes
Feb 27, 2026
Contributor
|
Thanks, rebased. |
timhoffm
approved these changes
Feb 27, 2026
Member
|
Is this worth a what's new entry? Or do you want to craft an overall "Performance improvements" entry for all of your optimizations? |
Contributor
Author
|
I might try to spin up the benchmark suite and see if we can get a major version comparison. Don't think each one of these needs a what's new. |
QuLogic
reviewed
Feb 27, 2026
93510ed to
db5d62c
Compare
Fix tests
More robust BBox creation
Revert "Prefer np.vstack().T to np.column_stack() for speed" This reverts commit 2e32436. Simplify column stack
db5d62c to
5df90ed
Compare
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
I've been having a lot of fun profiling the past two days. This PR is the result of optimizing slow bits of the text rendering code paths that are called downstream of
axis3d._draw_ticks(). None of these changes are 3D specific, so they should speed up 2D draw times as well. The non-agg-rendering code in this part of the stack is sped up by a cumulative 2.2x, which is an 8% reduction in the total draw time for my test script of an empty 3D plot.The commits are all self-contained, so I can break them apart if that's easier to review.
The font property cache is the change where I'm least confident in my understanding of the original design decisions, but it's simpler and 2x faster.The new__copy__method does help partially speed things up if we want to keep the original structure insteadSummary of the changes:
text.py:Rework the font property cache to use a plain dict instead oflru_cache@lru_cachefor rotation transforms via a_rotate(theta)helper function (common case is only a few angles)font_manager.py:__copy__method onFontPropertiesthat bypasses__init__validation__hash__more robust to new attrslines.pybroadcast_arrays.Tunpacking with column slicing for viewspath.pyInline shape validation instead of calling_api.check_shapetransforms.pyBbox.from_extentsBefore:

After (less time on things that aren't

draw_text):Test script:
PR checklist