PERF: Speed up ticks processing when not visible or using a NullLocator#30995
Conversation
There was a problem hiding this comment.
If this improves speed ok.
But overall it's quite weird that it does and to me it's an indicator that we have some fundamental issues with ticks.
What exactly does the trick? _tick_group_visible or the NullLocator? I would have expected that NullLocator (i.e. major_locs == []) should not incur notable costs. format_ticks(()); get_major_ticks(0), loop over a 0-length zip should all be no cost.
By default the major ticks are on and the minor ticks of. Do you get the speed just from the minor tick branch?
Anyway a substantial cost will remain for the cases that do have ticks. Updating all ticks individually trough a loop and ticks consisting of multiple artists, that in turn have to be updated is vastly inefficient. I want to explicitly bring #5665 (comment) to attention again as a long term strategy to clean up all the tick mess.
Side note: Doc build errors are entries from https://github.com/matplotlib/matplotlib/blob/main/doc/missing-references.json.
Either the PR does change some line numbers (which regular invalidate the exceptions listed in missing-references.json), or it's something in the wake of sphinx 9.1, which has substantially reworked autodoc and known to cause issues in several docs.
|
All of the speed up in my profiling reference case comes from the minor ticks NullLocator path, mostly from not having to initialize the NullLocator object. Probably indicates some work that could be lazified, but I agree that efforts would be better spent with an overhaul. |
|
Quite interesting. |
f4c7cd4 to
85a77b6
Compare
|
Rebased to main |
…ticks_speedup
…ticks_speedup
PR summary
Towards #5665
This shortcuts major or minor ticks processing when they are set to not visible, or their locators are NullLocators. In theory, NullLocators just return an empty list, but in practice its parent class does a fair amount of work during initialization that we don't need.
Here's a representative profiling run looking at
_update_ticks(). The red circled bit shows the work done byget_minorticklocswhich is skipped with this PR, roughly 30% of the function call time. This is pretty significant since_update_ticksis called 3x per draw for 2D and 2x per draw for 3D plots. In my test script which draws an empty 3D plot, skipping minor ticks saves 5% of the total draw time.PR checklist