Title: PERF: Cache ticks and ticklabel bboxes within each draw cycle by scottshambaugh · Pull Request #31012 · matplotlib/matplotlib · GitHub
Open Graph Title: PERF: Cache ticks and ticklabel bboxes within each draw cycle by scottshambaugh · Pull Request #31012 · matplotlib/matplotlib
X Title: PERF: Cache ticks and ticklabel bboxes within each draw cycle by scottshambaugh · Pull Request #31012 · matplotlib/matplotlib
Description: PR summary Towards #5665 Currently we are calling _update_ticks() 3 times per axis every draw call, and _get_ticklabel_bboxes 2 times per axis. These calls take up about 35% of total draw time for an empty plot. We can eliminate 25% of total draw time by caching the results of these calculations every draw cycle. This introduces some state, but I think it's decently well guarded and the performance boost is definitely worth it. Before & After The circled red areas show the before & after runtime of axis._update_label_position within Axis.draw(). It runs after the cache values have been set by other functions, so we nearly completely eliminate its runtime. Before: After: Profiling script: import time import matplotlib.pyplot as plt fig, ax = plt.subplots() print("Timing...") start_time = time.perf_counter() for i in range(100): fig.canvas.draw() end_time = time.perf_counter() plt.close() print(f"Time taken: {end_time - start_time:.4f} seconds") PR checklist [n/a] "closes #0000" is in the body of the PR description to link the related issue new and changed code is tested [n/a] Plotting related features are demonstrated in an example [n/a] New Features and API Changes are noted with a directive and release note [n/a] Documentation complies with general and docstring guidelines
Open Graph Description: PR summary Towards #5665 Currently we are calling _update_ticks() 3 times per axis every draw call, and _get_ticklabel_bboxes 2 times per axis. These calls take up about 35% of total draw time for ...
X Description: PR summary Towards #5665 Currently we are calling _update_ticks() 3 times per axis every draw call, and _get_ticklabel_bboxes 2 times per axis. These calls take up about 35% of total draw time for ...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/31012
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2666dde9-345f-2c5b-4c2c-a55ff74917fa |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9734:3D2201:F2B846:1499471:6A5567A3 |
| html-safe-nonce | def1165849bf31833e890cc86c299b83e1f1a03fed6c73c893f57f9af8ba4c29 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzM0OjNEMjIwMTpGMkI4NDY6MTQ5OTQ3MTo2QTU1NjdBMyIsInZpc2l0b3JfaWQiOiI4MDExMzgzODcxNzM5NjE5MjM1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | dc570f513d6b567b4fe56bd50dbb394d44f4ab6d302ec681fe2225767208878d |
| hovercard-subject-tag | pull_request:3197513880 |
| 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/31012/files |
| twitter:image | https://avatars.githubusercontent.com/u/14363975?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/14363975?s=400&v=4 |
| og:image:alt | PR summary Towards #5665 Currently we are calling _update_ticks() 3 times per axis every draw call, and _get_ticklabel_bboxes 2 times per axis. These calls take up about 35% of total draw time for ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| 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 | 8201d0b7bc32164c4662de52242e463a356df543 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width