-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Axes.__init__ speedup #8626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Axes.__init__ speedup #8626
Conversation
Both these classes have called their own .cla() method in their .__init__() method, so don't call it again in Axes.cla() if doing Axes.__init__().
If the Axis was just created, calling Axis.cla is redundant because it just happened.
799946c
to
4801cbc
Compare
It turns out that subclasses (like I'm not sure if the same is true of |
This seems awkward. Couldn't we take advantage of |
I don't see how. If you mean use it directly, it doesn't hold the same information as what we need. The added flag indicates (essentially) "no settings have been changed from the default", but If you mean, write something similar to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks like a clean and minimally-invasive solution to a long-standing problem.
This appears to have broken lots of stuff on travis! https://travis-ci.org/matplotlib/matplotlib/builds/298909059 I'm going to revert, @QuLogic could you re-open the PR so we can run the changes against the latest revision of |
This reminds me all kind of strange fails I had faced a year ago at fixing the particular problem. |
PR Summary
As noted in #6664,
Axes.__init__
is fairly slow due to the eventual call toAxis.reset_ticks
. @efiring suggested lazy instantiation and @Kojoley was implementing, but I'm unsure of the status. In the meantime though, we still speed things up by avoiding callingcla
too many times.Using the example from #6664 with
v2.0.x
:and
master
is already a bit faster:The trouble with
Axes.__init__
is that it does a bit too much clearing;Axes.__init__
calls:Axes._init_axis
self.xaxis
andself.yaxis
Axis.__init__
->Axis.cla
(2 calls perAxes
)Axis
with two spines viaSpine.register_axis
Axis.cla
is called on the registeredAxis
(2Spine
* 2Axis
= 4 calls perAxes
)Axes.cla
- Necessary to finish initializing theAxes
in a clean state, though it's generic for any caller.self.xaxis.cla()
/self.yaxis.cla()
(2 calls perAxes
)self.spines[:].cla()
(2 spines perAxis
= 4 calls perAxes
)That makes 12 calls to
Axis.cla
for only 2Axis
objects. Adding some hidden argument to skip these calls as in this PR would reduce those calls by 6, though the speedup is only approximately 4 times:PR Checklist