question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use WebAssembly.instantiateStreaming instead of WebAssembly.compileStreaming

See original GitHub issue

Unfortunately 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:50 (25 by maintainers)

github_iconTop GitHub Comments

2reactions
sokracommented, May 13, 2018

This is fixed. We now use instantiateStreaming when possible. Falling back to compileStreaming + async instantiate for WASM-to-WASM dependency chains.

Falling back non-streaming variants when streaming is not supported by the browser.

2reactions
flagxorcommented, Feb 23, 2018

Raising new Instance higher than new Module might make sense.

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.

Could it be done with a console.warn to inform devs, instead of a hard fail for those situations?

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found