Skip to content
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

80% reduction in .wasm asset size #1683

Merged
merged 3 commits into from
Dec 22, 2021
Merged

80% reduction in .wasm asset size #1683

merged 3 commits into from
Dec 22, 2021

Conversation

texodus
Copy link
Member

@texodus texodus commented Dec 22, 2021

WASM assets gzip quite well when properly configured on your application's HTTP server via the Content-Encoding: gzip header, and you can even remove the on-the-fly gzip cost by pre-zipping the wasm and configuring your server appropriately, but

  • Content-Encoding: gzip doesn't affect the perceived size of the perspective inline (e.g. without the webpack-plugin) builds, especially in the developer's imagination (see Consume perspective with esbuild #1655). Also, the inlined base64 WASM payload as a string does not compress nearly as well as gzipping the original WASM.
  • CDNs generally don't recognize pre-gzipped assets (as they likely shouldn't).
  • Even with the build plugin, WASM assets sizes are large and perspective's build is complex enough without asking app developers to provide bespoke server support.

To mitigate this perception/complexity, this PR gzips Perspective's WASM assets during the build step, then uses fflate, a small (3kb) gzip Javascript library, to unzip the WASM content in Perspective's JavaScript client after downloading. The result is nearly 80% reduction in Perspective WASM asset size without the use of Content-Encoding, at the cost of a few ms of additional startup time (with a margin of error at 400ms+ on my tests).

  • umd/perspective.js inline single-JS build, 8.0mb -> 1.7mb
  • cdn/perspective.cpp.wasm plugin build, 6.0mb -> 1.3mb
  • cdn/perspective-viewer.js inline single-JS build, 4.2mb -> 3.2mb (most of this is monaco)
  • cdn/perspective_viewer_bg.wasm plugin build, 1.2mb -> 300kb

@texodus texodus changed the title WASM gzip in-process. 80% reduction in .wasm asset size Dec 22, 2021
@texodus texodus added the enhancement Feature requests or improvements label Dec 22, 2021
@texodus texodus merged commit c7ccd78 into master Dec 22, 2021
@texodus texodus deleted the gzip-wasm branch December 22, 2021 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant