Use async instantiateStreaming loading method #10
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.
TL;DR
Refactors the
createCompatibleModuleOutBundle
function to return the more efficient and asynchronous streaming method to load WebAssembly modules in the browser,WebAssembly.instantiateStreaming
.Why?
Most browsers will not synchronously compile wasm modules that are greater than 4KB on the main thread. Therefore, this library doesn't work when using any larger assembly applications unless loaded inside a worker.
Both Mozilla and Google now advocate using the
WebAssembly. instantiateStreaming()
t compile and instantiate a modules directly from a streamed underlying source viafetch()
.Notes
Interface:
Previously this function returned an
Promise
and not afunction
which returns aPromise
, this differs between the inline variant which does return a promise generating function. Therefore, there wasn't consistency between to two return values. This is confusing for consumers as your documentation and examples in the readme assume that you must first invoke the returned function.Therefore, I have refactored this method to also return a Promise generating function for consistency in your API. However, due to this, it should probably be releases as a major version as it's a breaking change.
Tests:
The repo's tests are currently in a broken state in master when cloning the repository from scratch and installing dependencies with
yarn
ornpm
. Therefore, I haven't been able to validate if the tests pass after this change. Any help fixing the underlying issue with the dependencies would be greatly appreciated. See #9 for more detail.