Rollup plugin für WASM Inlining

Based on my experience with WASM, I’ve written my own Rollup plugin.

A few years ago, there was an article here that introduced an innovative approach to JSON compression called brotli-unicode. Now that I’ve had to get to grips with WASM, it made sense to use it to compensate for the shortcomings described.

The result is a plugin for Rollup that significantly simplifies the bundling of WASM files by simply integrating the file into the generated JavaScript file (inline), without the classic drawbacks of Base64 encoding (33–37% increase in size).

Comparative figures

This comparison is based on the implementation from this blog post, which includes OxiGraph and the HDT Rust module.

Without plugin

Size (bytes) File
1,191,284 wikidata-hdt/dist/client-sparql.js
2,609,124 wikidata-hdt/dist/client-sparql.js.map
714 wikidata-hdt/dist/client-sparql.scss
181,638 wikidata-hdt/dist/hdt_bg.wasm
3,954,968 wikidata-hdt/dist/web_bg.wasm

Ohne das Plugin werden die Datei wikidata-hdt/dist/client-sparql.js sowie beide WASM-Dateien benötigt. Insgesamt 5.327.890 Byte.

With plugin

Size (bytes) File
3,060,899 wikidata-hdt/dist/client-sparql.js
4,493,750 wikidata-hdt/dist/client-sparql.js.map
714 wikidata-hdt/dist/client-sparql.scss
181,638 wikidata-hdt/dist/hdt_bg.wasm
3,954,968 wikidata-hdt/dist/web_bg.wasm

The plugin requires only the file wikidata-hdt/dist/client-sparql.js. Total size: 3,060,899 bytes. This corresponds to approximately 57.4% of the original size.

The plugin is available via NPM, and the source code is available on GitHub.