Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX Speed up constrained layout #10658

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

Merged
merged 1 commit into from
Mar 4, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 3, 2018

PR Summary

As pointed out by @anntzer constrained layout gets slow for many subplots. Some slowdown is to be expected, but there were numerous redundant constraints being added, so this now has watchdogs to make sure only one constraint is added. Also some (probably insignificant) optimizations to reduce the number of calculations.

"closes" #10655

  • subplots(4, 4) took 4s now 1.8s
  • subplots(5, 5) took 12s, now 3.3s
  • subplots(6, 6) took 30s, now 6.3s

Still not quite linear in N, but a lot better than N*2 which it was before.

import matplotlib.pyplot as plt
import timeit

start = timeit.default_timer()

fig, ax = plt.subplots(6, 6, constrained_layout=False)
fig.canvas.draw()
stop = timeit.default_timer()
print(stop-start)

PR Checklist

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

@jklymak jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Mar 3, 2018
@jklymak
Copy link
Member Author

jklymak commented Mar 3, 2018

  • subplots(4, 4) took 4s now 1.8s
  • subplots(5, 5) took 12s, now 3.3s
  • subplots(6, 6) took 30s, now 6.3s

Still not quite linear in N, but a lot better than N*2 which it was before.

@jklymak jklymak added this to the v2.2.1 milestone Mar 3, 2018
@jklymak
Copy link
Member Author

jklymak commented Mar 3, 2018

This need not go out tomorrow (or whenever 2.2 goes out), but it would be nice to speed this up sooner rather than later.

@jklymak jklymak force-pushed the fix-speedup-constrainedlayout branch 4 times, most recently from c7dde59 to 85215d9 Compare March 3, 2018 17:53
Copy link
Member

@efiring efiring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As essentially part of the original PR, this is a special case: it's new and independent functionality that is complicated enough to make it very hard to review in detail. But the tests pass, and it is making a big speedup, so I am inclined to trust it and get it in ASAP, so it can start getting a real-world workout.

colnummin = 0*np.zeros(len(axs), dtype=np.int8)
colnummax = 0*np.zeros(len(axs), dtype=np.int8)
width = 0*np.zeros(len(axs))
height = 0*np.zeros(len(axs))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you multiplying all these "zeros" arrays by zero?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐑 Because I was multiplying by the axs array first but that didn’t work and then forgot to remove. I’ll fix when I get home.

@jklymak jklymak force-pushed the fix-speedup-constrainedlayout branch from 85215d9 to 4f69414 Compare March 4, 2018 00:33
@tacaswell tacaswell modified the milestones: v2.2.1, v2.2.0 Mar 4, 2018
@tacaswell tacaswell merged commit b5391ce into matplotlib:master Mar 4, 2018
lumberbot-app bot pushed a commit that referenced this pull request Mar 4, 2018
tacaswell added a commit that referenced this pull request Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants