Cache various dviread constructs globally. - #10954
Conversation
There was a problem hiding this comment.
shouldn't this be a property to be backward compatible?
85fb163 to
5719548
Compare
jklymak
left a comment
There was a problem hiding this comment.
This seems fine to me, but I don't understand all the details.
5719548 to
343a672
Compare
|
rebased |
343a672 to
776fcb3
Compare
|
|
||
| def __init__(self, filename): | ||
| @lru_cache() | ||
| def __new__(cls, filename): |
There was a problem hiding this comment.
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.
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.
@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

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