Skip to content

WebAssembly.Instance is disallowed on the main thread, if the buffer size is larger than 8MB #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MichaelBelousov opened this issue Apr 23, 2025 · 1 comment

Comments

@MichaelBelousov
Copy link

I have a WebAssembly blob which includes a very large codebase, so while it's 6.6MB release small, it's >200MB in debug mode, which started triggering the following error in chromium:

RangeError: WebAssembly.Instance is disallowed on the main thread, if the buffer size is larger than 8MB. Use WebAssembly.instantiate, or use the flag `--enable-features=WebAssemblyUnlimitedSyncCompilation`.

With this stack:

instantiateWebAssembly (module-loading.js:148)
await in instantiateWebAssembly
(anonymous) (module-loading.js:152)
loadModule (module-loading.js:166)
(anonymous) (js.zig:9714)

Using [email protected]

Skimming the code, it looks like there's probably an option that can get around this, but I don't see anything in the documentation. How can I best get around this?

@MichaelBelousov
Copy link
Author

FWIW here's a very ugly zigar-runtime patch to get around it:

diff --git a/dist/features/module-loading.js b/dist/features/module-loading.js
index 82655b699395e5a556d34447b8ddbceb27a6fd65..69287312a98c251435a49f7b69d2b99b2bce44e2 100644
--- a/dist/features/module-loading.js
+++ b/dist/features/module-loading.js
@@ -145,7 +148,10 @@ var moduleLoading = mixin({
         shared: multithreaded,
       });
       this.initialTableLength = tableInitial;
-      return new w.Instance(executable, exports);
+      return WebAssembly.instantiateStreaming(fetch(res.url), exports).then(w => w.instance);
     },
     loadModule(source, options) {
       return this.initPromise = (async () => {

Of course I think this is just temporary, and a better solution is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant