-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Cache various dviread constructs globally. #10954
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
lib/matplotlib/textpath.py
Outdated
enc = dviread.Encoding(enc_name) | ||
return {c: i for i, c in enumerate(enc.encoding)} | ||
@cbook.deprecated("3.0") | ||
def tex_font_map(self): |
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.
shouldn't this be a property to be backward compatible?
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.
yup, fixed
85fb163
to
5719548
Compare
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.
This seems fine to me, but I don't understand all the details.
5719548
to
343a672
Compare
rebased |
343a672
to
776fcb3
Compare
@@ -808,14 +812,14 @@ class PsfontsMap(object): | |||
""" | |||
__slots__ = ('_font', '_filename') | |||
|
|||
def __init__(self, filename): | |||
@lru_cache() | |||
def __new__(cls, filename): |
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.
This seems a bit dodgy. Would a helper function (still using lru_cache) also work here instead of decorating __new__
?
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.
Something like
@lru_cache()
def _psfontmap_factory(filename): return PsfontsMap(filename)
and use the factory function instead? TBH that seems worse to me but if you prefer that form let me know (but I'm not sure I got what you mean).
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.
@tacaswell and I talked, and while this, as a gut reaction, feels a bit magical, it's probably the best mix of being direct and magical, versus other solutions. It wouldn't hurt to have a comment or two here, but I'm not going to hold this up for that.
Decorating |
Previously, caching was done at the level of the renderer, so new renderers would have to reconstruct the PsfontsMap and Adobe encoding tables. Using a global cache greatly improves the performance: something like rcdefaults() gca().text(.5, .5, "$foo$", usetex=True) %timeit savefig("/tmp/test.svg") goes from ~187ms to ~37ms. %timeit savefig("/tmp/test.pdf") goes from ~124ms to ~53ms. Also moves TextToPath's _get_ps_font_map_and_encoding to use a standard lru_cache.
776fcb3
to
cb58589
Compare
Marking as release critical as it already has one positive review and the gain in performance is quite big. |
Previously, caching was done at the level of the renderer, so new
renderers would have to reconstruct the PsfontsMap and Adobe encoding
tables. Using a global cache greatly improves the performance:
something like
goes from ~187ms to ~37ms.
goes from ~124ms to ~53ms.
Also moves TextToPath's _get_ps_font_map_and_encoding to use a standard
lru_cache.
PR Summary
PR Checklist