Support async instantiation in Node.js - #27730
Draft
jeremy-code wants to merge 2 commits into
Draft
jeremy-code wants to merge 2 commits into
jeremy-code wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since Node.js is on v8, which optimizes
instantiateStreamingsignificantly due to caching,123 async instantiation should be preferred. While Node.js doesn't support file URIs, a file system read stream can still be used as an input forinstantiateStreaming, so as long as the MIME type is set correctly (this same technique is used incosInstantiateStream).Unidici does support using a Node.js read stream in the Response constructor (see here). I believe this means this should be valid in all Node.js environments. If there somehow is an issue (maybe in an edge environment where some Node polyfill exists, but the native web Response is still used...?), this could be fixed either by:
Readable.toWeb()fromnode:streamfs.openAsBlob()instead (might have some weird issues on older Node.js versions since blobs used to be stored in memory in Node File-based Blob implementation nodejs/node#45188)Let me know what you think.
Footnotes
https://v8.dev/blog/wasm-code-caching ↩
https://web.dev/articles/loading-wasm ↩
MDN warns "This method is not the most efficient way of fetching and instantiating Wasm modules. If at all possible, you should use the newer WebAssembly.instantiateStreaming() method instead": https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/instantiate_static ↩