80% reduction in .wasm
asset size
#1683
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, butContent-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 withesbuild
#1655). Also, the inlined base64 WASM payload as a string does not compress nearly as well as gzipping the original WASM.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 ofContent-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