Use WebAssembly.instantiateStreaming instead of WebAssembly.compileStreaming
See original GitHub issueUnfortunately there are performance issues with WebAssembly.compileStreaming
on iOS. On iOS devices, there is a limited amount of faster memory. Because of this, the engine doesn’t know which kind of memory to compile for until instantiate
is called.
If I understand correctly, for the JSC engine compileStreaming
will just do a memcopy of the .wasm. It’s only when instantiate
is called that the Memory object is created. Then the engine knows whether it will be using the fast memory, or just a normal malloc’d Memory that needs bounds checks. At this point, it can generate the code appropriately.
Because of this, we plan to recommend that all bundlers use instantiateStreaming
instead. Does this cause any issues for webpack?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:50 (25 by maintainers)
Top Results From Across the Web
WebAssembly.compileStreaming() - MDN Web Docs
The WebAssembly.compileStreaming() function compiles a WebAssembly.Module directly from a streamed underlying source.
Read more >Loading WebAssembly modules efficiently - web.dev
When working with WebAssembly, you often want to download a module, compile it, instantiate it, and then use whatever it exports in JavaScript....
Read more >Loading WebAssembly Modules in JavaScript | by Urvashi
WebAssembly.compileStreaming() also only compiles a WebAssembly module, but it uses streaming similar to instantiateStreaming() thus eliminating the ...
Read more >Using the Streaming WebAssembly APIs | Manual - Deno
instantiateStreaming ( fetch("https://wpt.live/wasm/incrementer.wasm"), ) ... work on the module before instantiation you can instead use compileStreaming :.
Read more >Loading and running WebAssembly - OpenHome.cc
In previous documents, you use Fetch API to fetch .wasm file. The returned Promise instance of fetch is passed into WebAssembly.instantiateStreaming .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is fixed. We now use
instantiateStreaming
when possible. Falling back tocompileStreaming
+ asyncinstantiate
for WASM-to-WASM dependency chains.Falling back non-streaming variants when streaming is not supported by the browser.
Though we’d need to be thoughtful about leaving latitude for different implementation strategies (like compile at instantiate). Lowering the limit once it’s been raised would be hard. It seems like for modules, being able to use instantiateStreaming is ideal.
In general, I’ve been encouraged to have less chatty things on the console by devtools folks. Not sure this is always ideal. I often wish we had similarly verbose compilation and caching info to Firefox for asm.js/wasm. Though for this one it might make sense.