-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Support WebAssembly.instantiateStreaming #21130
Comments
The design of instantiateStreaming currently requires |
While I understand that implementing WebAssembly for isomorphism might be good, but, for native modules, we already have Native and N-API addons. This would just be throwing another one into the mix. |
@AyushG3112 we already support wasm, this would just be adding another method of loading it. |
@devsnek ah, I did not know that. Nevermind my comment then, and thanks! |
What is the use case besides feature parity with browsers?
That would be fairly straightforward to implement but I share @devsnek's sentiment that we shouldn't diverge from browsers lightly.
Pray tell! |
@devsnek @bnoordhuis I totally agree. |
Okay, but can you speak to your use case? As I said, I don't really see when or why you'd use it with Node.js. |
@bnoordhuis My use case is image processor what work on browser and Node.js implemented by WebAssembly. BTW, I think we decide to implement Fetch API or not prior to start this discussion. |
I can see why you'd load it in streaming fashion in a browser but why in Node.js? If it's an on-disk file, just load it in one go. |
@bnoordhuis |
What if the WebAssembly loading and instantiation is done is a separate worker and posted to the main thread? Also FYI https://github.com/wasm-tool/node-loader. I know that @bmeck is working a multi-threaded loading which would fit well to this use case. |
This commit adds InstantiateStreaming support to allow for some compatability with Web browser environments. Refs: nodejs#21130
Is this something Node.js is likely to implement? If not, should we close this? |
I'm going to mark this as stalled and close it. Feel free to comment or re-open if you believe that's the wrong thing to do here. |
It's sad that Node doesn't support this method. 😐 |
I am sure we would consider a PR if you were to implement it. |
good start here: https://github.com/devsnek/node/tree/feature/wasm-streaming |
👀 |
Refs: nodejs#41749 Fixes: nodejs#21130 PR-URL: nodejs#42701 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
I think it's better support
WebAssembly.instantiateStreaming
.It makes more easy to use WebAssembly and we can get more compatibility for Web.
It already implemented in Google Chrome, Firefox and some browsers.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
instantiateStreaming
already exists indeps/v8/src/wasm/wasm-js.cc
but cannot cover this branch.node/deps/v8/src/wasm/wasm-js.cc
Lines 1177 to 1182 in de73272
To cover this branch, we must call
SetWasmCompileStreamingCallback
.node/deps/v8/include/v8.h
Line 7805 in de73272
node/deps/v8/src/api.cc
Lines 8876 to 8877 in de73272
In chromium, implemented here:
https://github.com/chromium/chromium/blob/51459d663d841c6430747aec97be9f7e7a7ca41f/third_party/blink/renderer/bindings/core/v8/v8_wasm_response_extensions.cc#L194-L222
And use it here:
https://github.com/chromium/chromium/blob/51459d663d841c6430747aec97be9f7e7a7ca41f/third_party/blink/renderer/bindings/core/v8/v8_wasm_response_extensions.cc#L228
Why we must inject the actual implementation,
It's said that this is for layering reasons.
WebAssembly/design#1085
Discussion
instantiateStreaming
compatible with design.instantiateStreaming(fs.promises.readFile('./some.wasm'), importObject)
Buffer
, notArrayBuffer
.The text was updated successfully, but these errors were encountered: