-
Notifications
You must be signed in to change notification settings - Fork 694
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
There should be a way to abort wasm compilation #1262
Comments
Note that Promise and Fetch run on the main thread, whereas Wasm compilation (if asynchronous) can be done in background, only the instantiation is blocking. Also I'm wondering what happens when an module (while compiling) gets garbage collected. |
Yes, but the problem is not main thread blocking, but unnecessary operations (fetch also doesn't block main thread). Also it's related to any host, not just browsers. |
Good question. I think we can test this case aborting fetch while |
In Firefox the JS WasmModule object is a front for an internal Module object which is shared among the threads that have a handle to the module; the object is (atomically) refcounted. When the JS WasmModule object is GC'd it just drops its refcount on the Module, but any ongoing background compilation has a reference to the Module object and will keep it alive until the compilation is finished. |
Is there any plan to stop the compilation in that case? I don't know how common that situation will be. |
V8 does it very similarly, except that compilation does not keep the module alive. We cancel compilation when the ref count drops to zero. |
If you use the wasm streaming JS APIs, I think this already Just Works. E.g., if you have:
then if you For the |
@lukewagner this won't work for Node.js and other non-browser environments. |
You're right, the streaming APIs are in the Web API, but I'm not sure if the solution is to have wasm's JS API to invent its own duplicate version of |
Cancellation won't be possible at all until we'll have an API for that in (Could we add JS embedding label for the issue?) |
We now have at least one precedent of using |
Web Locks API also uses Related discussions:
|
Compilation (and instantiation?) of WebAssembly module could be a resource intensive operation so there should be a way for wasm hosts to abort this step in cases when module is not needed anymore for some reasons.
As for JS hosts, theoretically cancellation methods should be in JS API, but JS doesn't have cancellation mechanism for promises yet. There are AbortController and AbortSignal which are used to abort Fetch. Probably they can be used to abort wasm compilation (passing signal as extra parameter to
WebAssembly.compile
), but they are part of DOM WHATWG spec, so it's only possible to use them in browsers and as a consequence only in Web API.The text was updated successfully, but these errors were encountered: