Skip to content
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

Low-hanging performance improvements #5664

Merged
merged 7 commits into from
Dec 22, 2015
Merged

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Dec 11, 2015

Instantiating Paths is expensive, but they aren't mutable, so just reuse
when possible.

WeakValueDictionaries are expensive to construct. We can fix that by
handling the weakrefs ourself.

And cbook.popall has no reason to exist. Maybe someone's using it and it should stay, but no one should be using it.

On my benchmark of:

plt.subplots(8, 8)
plt.savefig("test.png")

I get a speedup from 5.04s to 3.81s.

Instantiating Paths is expensive, but they aren't mutable, so just reuse
when possible.

WeakValueDictionaries are expensive to construct.  We can fix that by
handling the weakrefs ourself.
@mdboom
Copy link
Member Author

mdboom commented Dec 22, 2015

I think this is finally ready-to-merge.

# turn the weakkey dictionary into a normal dictionary
d['_parents'] = dict(six.iteritems(self._parents))
# turn the dictionary with weak values into a normal dictionary
d['_parents'] = dict((k, v()) for (k, v) in
Copy link
Member

Choose a reason for hiding this comment

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

Does this need a check that v() returns an active ref?

Copy link
Member Author

Choose a reason for hiding this comment

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

I currently check on deserializing (__setstate__) where you have to deal with it. No real need to do it in both places unless we really care about the size of the serialization.

Copy link
Member

Choose a reason for hiding this comment

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

fair enough.

@tacaswell tacaswell added this to the proposed next point release (2.1) milestone Dec 22, 2015
tacaswell added a commit that referenced this pull request Dec 22, 2015
PRF: Low-hanging performance improvements
@tacaswell tacaswell merged commit 50ce5ff into matplotlib:master Dec 22, 2015
@@ -93,6 +93,8 @@
(TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN,
CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN) = list(xrange(8))

_empty_path = Path(np.empty((0, 2)))
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, there is a fast instantiation route for Paths: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/path.py#L173.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants