wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
https://wasmer.io
MIT License
18.53k stars 793 forks source link

Wasmer 3.3 js failes to load module when size above 4KB on Chromium #3974

Closed kobyhallx closed 2 months ago

kobyhallx commented 1 year ago

Describe the bug

Wasmer 3.3 js failes to load module when size above 4KB on Chromium/Chrome

wasmer::js::module: Error while compiling JsValue(RangeError: 
WebAssembly.Compile is disallowed on the main thread, if the buffer size is larger than 4KB. 
Use WebAssembly.compile, or compile on a worker thread.
RangeError: WebAssembly.Compile is disallowed on the main thread, if the buffer size is larger than 4KB. 
Use WebAssembly.compile, or compile on a worker thread.

Steps to reproduce

Call Module::new on Chromium/Chrome with bytes sized above 4KB.

Expected behavior

Executes Module::new just fine.

...or exposes more appropriate async functions. ...or allows to pass native Objects (Module&Instance)

Actual behavior

Panics with #3973

Additional context

at 5eeda45 Release 3.3.0 (https://github.com/wasmerio/wasmer/pull/3842)

ptitSeb commented 1 year ago

Can you give a more precise example of what your doing to trigger that error @kobyhallx ?

kobyhallx commented 1 year ago

@ptitSeb here's specific code https://github.com/noir-lang/acvm-simulator/blob/master/src/barretenberg/mod.rs#L257

size of that wasm is around 5MB.

theduke commented 1 year ago

@kobyhallx the error is pretty clear, Chrome forbids loading large wasm modules on the main browser thread.

You need to offload the module parsing to a worker.

Here is some related info: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

If you want to do that from Rust you can use https://docs.rs/web-sys/latest/web_sys/struct.Worker.html .

theduke commented 1 year ago

I guess it would make sense to add an async version of Module::new() for the Javascript implemenetation, which uses WebAssembly.compile() under the hood.

That would work similar to the NativeEngineExt, in that it would add backend specific functionality through an extension trait.

I don't think we'll have capacity to do that ourselves soon though.

But I'm sure we'd be happy to accept a PR.

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 months ago

Feel free to reopen the issue if it has been closed by mistake.

theduke commented 2 months ago

I believe taking inspiration from the new wasmer-js SDK should be sufficient.