Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 3 commits intomatplotlib:masterfromQuLogic:Axes-init-speedup
Nov 8, 2017
Merged

Conversation

QuLogic
Copy link
Member

@QuLogicQuLogic commentedMay 16, 2017
edited
Loading

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 withv2.0.x:

$ python3 -m timeit \  -s "from matplotlib.figure import Figure; from matplotlib.axes import Axes; fig = Figure()" \  "Axes(fig, (0, 0, 1 ,1))"10 loops, best of 3: 29.7 msec per loop

andmaster is already a bit faster:

$ python -m timeit \  -s "from matplotlib.figure import Figure; from matplotlib.axes import Axes; fig = Figure()" \  "Axes(fig, (0, 0, 1 ,1))"100 loops, best of 3: 17.7 msec per loop

The trouble withAxes.__init__ is that it does a bit too much clearing;Axes.__init__ calls:

  • Axes._init_axis
    • Createsself.xaxis andself.yaxis
      • Axis.__init__ ->Axis.cla (2 calls perAxes)
    • Registers eachAxis 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 makes12 calls toAxis.cla for only2Axis 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:

$ python -m timeit \  -s "from matplotlib.figure import Figure; from matplotlib.axes import Axes; fig = Figure()" \  "Axes(fig, (0, 0, 1 ,1))"100 loops, best of 3: 4.45 msec per loop

PR Checklist

  • [N/A] Has Pytest style unit tests
  • Code is PEP 8 compliant
  • [N/A] New features are documented, with examples if plot related
  • [N/A] Documentation is sphinx and numpydoc compliant
  • [N/A] Added an entry to doc/users/whats_new.rst if major new feature
  • [N/A] Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@QuLogicQuLogic added this to the2.1 (next point release) milestoneMay 16, 2017
Both these classes have called their own .cla() method in their.__init__() method, so don't call it again in Axes.cla() if doingAxes.__init__().
If the Axis was just created, calling Axis.cla is redundant because itjust happened.
@QuLogic
Copy link
MemberAuthor

QuLogic commentedMay 16, 2017
edited
Loading

It turns out that subclasses (likePolarAxes) tend to override theircla method, so changing their signature is dangerous. Instead, I added an attribute that indicates that the class is still in its__init__ phase.

I'm not sure if the same is true ofSpine.register_axis, but seen an error and thus haven't changed it back.

@WeatherGod
Copy link
Member

This seems awkward. Couldn't we take advantage ofself.stale instead?

@QuLogic
Copy link
MemberAuthor

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", butself.stale means "current settings are different from what was drawn". It has no relationship with default settings for us to use.

If you mean, write something similar toself.stale, that's a lot of work for very little gain and seems rather non-trivial and error-prone to me.

@tacaswelltacaswell modified the milestones:2.2 (next next feature release),2.1 (next point release)Aug 29, 2017
@efiring
Copy link
Member

I'm starting to think that the approach to reducing the redundantcla calls here is better than the way I did it in#8752. If so, we should merge this (or a modification of it) and I can change#8752 accordingly. (It needs some more work, but I still want to get that one in, too.)

Copy link
Member

@efiringefiring left a 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.

@tacaswelltacaswell merged commit1636bed intomatplotlib:masterNov 8, 2017
@QuLogicQuLogic deleted the Axes-init-speedup branchNovember 8, 2017 04:11
@dstansby
Copy link
Member

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 ofmaster?

@Kojoley
Copy link
Member

This reminds me all kind of strange fails I had faced a year ago at fixing the particular problem.

@QuLogicQuLogic restored the Axes-init-speedup branchNovember 21, 2017 09:52
@efiringefiring mentioned this pull requestDec 4, 2017
6 tasks
@QuLogicQuLogic modified the milestones:needs sorting,v2.2.0Feb 13, 2018
@QuLogicQuLogic deleted the Axes-init-speedup branchApril 16, 2021 21:54
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@efiringefiringefiring approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v2.2.0
Development

Successfully merging this pull request may close these issues.

6 participants
@QuLogic@WeatherGod@efiring@dstansby@Kojoley@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp