Title: Improve matplotlib.pyplot importtime by caching ArtistInspector by eendebakpt · Pull Request #23686 · matplotlib/matplotlib · GitHub
Open Graph Title: Improve matplotlib.pyplot importtime by caching ArtistInspector by eendebakpt · Pull Request #23686 · matplotlib/matplotlib
X Title: Improve matplotlib.pyplot importtime by caching ArtistInspector by eendebakpt · Pull Request #23686 · matplotlib/matplotlib
Description: PR Summary During import of matplotlib.pyplot the ArtistInspector performs actions for objects of type Artist. Several actions are performed twice and can be avoided by caching the result. This PR improves the import time from by 1149 ms to 808 ms (the numbers are system dependent, quoted numbers are on Windows with python 3.10). The PR consists of 3 elements: Adding a lru_cache to ArtistInspector.is_alias. Creating a cached method ArtistInspector.number_of_parameters( for len(inspect.signature(func).parameters) Creating a method getdoc_pure that is equal to inspect.getdoc, but without an expensive call to inspect.cleandoc. Notes: This part of the code was identified by using https://github.com/asottile/importtime-waterfall and https://jiffyclub.github.io/snakeviz/. Analysis of the data shows there are several other places where the import time can be improved, but that is for another PR. The usage of caching adds some memory overhead, but not a lot. This can be inspected for this PR by import matplotlib.artist c=matplotlib.artist.ArtistInspector.is_alias c.cache_info() Timings are obtained using python -c "import time; t0=time.perf_counter(); import matplotlib.pyplot; dt=time.perf_counter()-t0; print(f'{1e3*dt:.2f} ms')" The method ArtistInspector.get_valid_values is still a quite expensive method that is called during startup. The full docstring is used there, so it could not easily be refactored. PR Checklist Tests and Styling Has pytest style unit tests (and pytest passes). Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all). Documentation New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there). No new feature
Open Graph Description: PR Summary During import of matplotlib.pyplot the ArtistInspector performs actions for objects of type Artist. Several actions are performed twice and can be avoided by caching the result. This PR ...
X Description: PR Summary During import of matplotlib.pyplot the ArtistInspector performs actions for objects of type Artist. Several actions are performed twice and can be avoided by caching the result. This PR ...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/23686
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:855df5c5-57b6-7461-364c-80808ecaeeba |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D8FC:814DC:4184:54BA:6A52E74A |
| html-safe-nonce | 22660184d431b133d5971cb053095e2e89cbb354b3236191e919426942f8e316 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOEZDOjgxNERDOjQxODQ6NTRCQTo2QTUyRTc0QSIsInZpc2l0b3JfaWQiOiI4MjI3MjU0NzEzMzU3MzYzMDE4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 245ac632b4966e883b632784a57bdfb7d98e046cacf992546b59012716514e9a |
| hovercard-subject-tag | pull_request:1031877616 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/23686/files |
| twitter:image | https://avatars.githubusercontent.com/u/883786?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/883786?s=400&v=4 |
| og:image:alt | PR Summary During import of matplotlib.pyplot the ArtistInspector performs actions for objects of type Artist. Several actions are performed twice and can be avoided by caching the result. This PR ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width