Title: Faster image generation in WebAgg/NbAgg backends by mdboom · Pull Request #5389 · matplotlib/matplotlib · GitHub
Open Graph Title: Faster image generation in WebAgg/NbAgg backends by mdboom · Pull Request #5389 · matplotlib/matplotlib
X Title: Faster image generation in WebAgg/NbAgg backends by mdboom · Pull Request #5389 · matplotlib/matplotlib
Description: Write the PNG data to string buffer, rather than an io.BytesIO to eliminate the cost of memory reallocation Add compression and filter arguments to _png.write_png Use compression=3 and filter=NONE, which seems to be a sweet spot for processing time vs. file size Most of the speed increase comes from this last point. There are two knobs that libpng provides: compression level, which is just the zlib lossless compression level 0-9, and filter, which is described here: http://www.w3.org/TR/PNG-Filters.html While the PNG standard says that the filter is to prepare the image for optimum compression, for typical plotting images which have lots of solid colors, it actually appears to make compression worse. (I suspect the filtering helps mainly on photographic images). Worse yet, the algorithm that automatically determines which filtering algorithm will be optimal takes a significant amount of runtime overhead. By selecting an algorithm explicitly, we can eliminate that overhead entirely. To benchmark, I used a series of 16 difference images collected directly from a WebAgg session. I then ran these images through different combinations of compression and filter and compared the runtime and resulting file sizes. These benchmark images are available at mdboom/webagg-speed. The results are below: The behavior prior to this PR was compression of 6, filter of "auto", which corresponds to the "X" at time ~2.2s in the plot. After this PR, I've changed it to compression of 6, filter of "NONE", which seems like a good low risk choice. It is not significantly worse in terms of data size, and more than 4x better in runtime. One could be more aggressive on runtime by decreasing compression to 1 or 2 at the expense of a little file size, but that could be detrimental over a low bandwidth connection.
Open Graph Description: Write the PNG data to string buffer, rather than an io.BytesIO to eliminate the cost of memory reallocation Add compression and filter arguments to _png.write_png Use compression=3 and filter=NONE,...
X Description: Write the PNG data to string buffer, rather than an io.BytesIO to eliminate the cost of memory reallocation Add compression and filter arguments to _png.write_png Use compression=3 and filter=NONE,...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/5389
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7fe579c4-c925-abf2-d0d5-3a6c8a8e88d6 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9AF8:28210C:216036:2E5ECD:6A546B5E |
| html-safe-nonce | 0d7d62b6228a5f727538aa8f7de8a69be6c36e7e223ee92611ba36fc9df198a0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUY4OjI4MjEwQzoyMTYwMzY6MkU1RUNEOjZBNTQ2QjVFIiwidmlzaXRvcl9pZCI6IjgwOTQyMDEzMDM3NDY3Njc3MTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 65d13a7a365c06ed4e5bf3d01940e90630493ede102926802d4ebf90ab46039f |
| hovercard-subject-tag | pull_request:49568542 |
| 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/5389/files |
| twitter:image | https://avatars.githubusercontent.com/u/38294?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/38294?s=400&v=4 |
| og:image:alt | Write the PNG data to string buffer, rather than an io.BytesIO to eliminate the cost of memory reallocation Add compression and filter arguments to _png.write_png Use compression=3 and filter=NONE,... |
| 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 | 6d28624802c2f7d9500239dd6870ed7031b7353b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width