Skip to content

Memoize parse_fontconfig_pattern; speeds up test suite by ~1min. #8252

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
Mar 11, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 10, 2017

On my laptop this patch drops the duration of the test suite from 604s
to 554s (with the inkscape patch on as well).

(The fontconfig syntax is simple enough that one could also probably write a simple regex parser.)

attn @NelleV

# repeatedly called when the rcParams are reset (to validate the default
# fonts). In practice, the cache size doesn't grow beyond a few dozen entries
# during the test suite.
parse_fontconfig_pattern = lru_cache()(FontconfigPatternParser().parse)

Copy link
Member

@QuLogic QuLogic Mar 10, 2017

Choose a reason for hiding this comment

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

Should be another blank line above the function (current ignore list is hiding this.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

On my laptop this patch drops the duration of the test suite from 604s
to 554s (with the inkscape patch on as well).
@anntzer anntzer force-pushed the memoize-parse_fontconfig_pattern branch from 263ac2a to d8ce993 Compare March 10, 2017 01:18
@anntzer
Copy link
Contributor Author

anntzer commented Mar 10, 2017

For the record I have also tried updating the cache on mathtext.parse to use a LRU cache (the current maxdict is a bit silly...). Even though that function seems to be another bottleneck currently (~12% total test time with the inkscape patch, without this patch), using a large cache does not appear to help whatsoever (whether with a max cache size of 256 or 1024, I get 1705 hits and 1659 misses, and the runtime is essentially the same).

This is probably due to the fact that most of that time is actually spent in test_mathtext.py (~20% total test time), which just throws a bunch of different things at the parser, so memoizing won't help.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Mar 10, 2017
@NelleV NelleV merged commit 6c934e6 into matplotlib:master Mar 11, 2017
@NelleV
Copy link
Member

NelleV commented Mar 11, 2017

Thanks @anntzer !

@anntzer anntzer deleted the memoize-parse_fontconfig_pattern branch March 11, 2017 20:26
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.

4 participants