Conversation
11ec7cd to
25811a7
Compare
5462669 to
a56570e
Compare
lib/matplotlib/axes/_base.py
Outdated
| # Use ._children and ._sticky_edges directly, because most extra | ||
| # artists in .get_children() (spines, titles, etc.) never have |
There was a problem hiding this comment.
We should formalize the concept of different categories of children. I would distinguish
- data children: basically
_children - auxiliary children: all supporing artists that are needed to draw the Axes itself.
Names and exact definitions to be bikeshed.
For a start here, I would create Axes._get_data_children() as a private method, so that we can better document what that is and dont have to go into the private _childrenof the shared axes. That would also make the comment part on_children` unnecessary, because what you are writing there is expressed through the code concept.
There was a problem hiding this comment.
I like that, updated
| x_sticky_lists = [] | ||
| for ax in x_shared: | ||
| for artist in (*ax._children, *ax._axis_map.values()): | ||
| sticky_edges = artist._sticky_edges |
There was a problem hiding this comment.
It does show up in the results - just the .sticky_edges property accesses are the circled bits in the baseline profiling here. Because autoscale_view is called for each scatter call in the script, this inner loop is O(n^2) with the number of artists. We could defer autoscaling or be smarter about which artists are on the boundary, but that would be a much bigger change.
ca433ff to
ff6d1d2
Compare
ff6d1d2 to
ac439c8
Compare
|
Rebased, hadn't realized I already made a portion of these changes in #31004 |

PR summary
This speeds up the sticky edges handling in
autoscale_view. Most artists do not have sticky edges, so:x_sticky_listsandy_sticky_lists, which saves us from having to concatenate a large number of empty arrays.This completely removes the time spent in the circled code paths here, about 60% of

_unstale_view_limand 15% of the total run time in this test script.Profiling test script:
AI Disclosure
PR checklist