-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Low-hanging performance improvements #5664
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
Conversation
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.
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 |
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.
Does this need a check that v()
returns an active ref?
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 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.
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.
fair enough.
PRF: Low-hanging performance improvements
@@ -93,6 +93,8 @@ | |||
(TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN, | |||
CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN) = list(xrange(8)) | |||
|
|||
_empty_path = Path(np.empty((0, 2))) |
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.
FWIW, there is a fast instantiation route for Paths: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/path.py#L173.
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:
I get a speedup from 5.04s to 3.81s.