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

Skip to content

Cache realpath resolution in font_manager. #18018

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
Jul 22, 2020
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 22, 2020

This shaves off ~33% runtime from

from pylab import *
import timeit

tx = figtext(.5, .5, "foo\nbar baz")
gcf().canvas.draw()
gcf().patch.set_visible(False)
r = gcf()._cachedRenderer
n, t = timeit.Timer(lambda: tx.draw(r)).autorange(); print(t / n, n, t)

because previously the calls to realpath were not cached and filesystem
access is slow.

(The font cache is likely already in trouble if fonts move in the
filesystem within the execution of a program given that there are other
layers of cache, so I wouldn't overly worry about that. At best we may
want to expose a manual function to invalidate all caches if someone
really runs into that problem.)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 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/next_api_changes/* if API changed in a backward-incompatible way

This shaves off ~33% runtime from
```python
from pylab import *
import timeit

tx = figtext(.5, .5, "foo\nbar baz")
gcf().canvas.draw()
gcf().patch.set_visible(False)
r = gcf()._cachedRenderer
n, t = timeit.Timer(lambda: tx.draw(r)).autorange(); print(t / n, n, t)
```
because previously the calls to realpath were not cached and filesystem
access is slow.

(The font cache is likely already in trouble if fonts move in the
filesystem within the execution of a program given that there are other
layers of cache, so I wouldn't overly worry about that.  At best we may
want to expose a manual function to invalidate all caches if someone
really runs into that problem.)
@jklymak jklymak merged commit 10ea266 into matplotlib:master Jul 22, 2020
@anntzer anntzer deleted the rpc branch July 22, 2020 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants