Aside: how is WebAssembly's binary form currently shipped? In a demo I saw yesterday it was written out inline as a Uint8Array of integers between 0-255. Even with gzip enabled this can't be very efficient.
For completely unrelated reasons, I was already thinking of adapting (my fork of) the LZ-string library[0] to directly compress/decompress typed arrays to "websafe" UTF16 strings, similar to the already existing `compressToUTF16` functionality in LZ-string. Essentially, the strings would represent LZ-compressed bitstreams, using 15 bits per string character.
Could this be useful for reducing the size of WASM binary when encoded in plain JavaScript? (the minified library would probably be around 1kb after gzip)
wasm files are already a binary format, an explicit Uint8Array should only only necessary if you want to inline the wasm directly with the JS that instantiates it.
Right, I thought it was odd; I remember reading that part of the big benefit of WASM was more compact, faster-to-parse source code. Going all the way up to text form and back down to binary data is at odds with that.
> an explicit Uint8Array should only only necessary if you want to inline the wasm directly with the JS that instantiates it.
Are there any realistic scenarios where this is the more sensible option?
Anyway, I should have searched MDN first, the relevant bit of documentation is pretty clear:
I suppose you could avoid having the extra request roundtrip by inlining a uint8array (or a base64 encoded string or something), and it also lets you have wasm and it's associated JS be put together which would automatically avoid cache/version mismatch without any extra work, but I would be surprised if that makes sense in any normal scenario.
For completely unrelated reasons, I was already thinking of adapting (my fork of) the LZ-string library[0] to directly compress/decompress typed arrays to "websafe" UTF16 strings, similar to the already existing `compressToUTF16` functionality in LZ-string. Essentially, the strings would represent LZ-compressed bitstreams, using 15 bits per string character.
Could this be useful for reducing the size of WASM binary when encoded in plain JavaScript? (the minified library would probably be around 1kb after gzip)
[0] https://github.com/JobLeonard/lz-string/tree/array-lookup
[1] http://pieroxy.net/blog/pages/lz-string/index.html#inline_me...