-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
src,v8: add wasm streaming handler api #42843
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
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this would be a good candidate for an embedder API?
If we really want to expose this as a JavaScript API, the documentation should be very clear about the security implications. Loading compiled code from an untrusted origin defeats all security properties of WebAssembly.
@@ -245,6 +245,16 @@ function setupFetch() { | |||
throw new ERR_WEBASSEMBLY_RESPONSE('body has already been used'); | |||
} | |||
|
|||
const handler = require('internal/v8').getWasmStreamingHandler(); | |||
const cached = await handler?.get(response.url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand this, this will only work when loading WebAssembly from a remote origin, and only if the URL is stable, and only if the WebAssembly module does not change.
if (streamState.setCompiledModuleBytes(cached)) { | ||
return; | ||
} else { | ||
await handler.delete(response.url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, V8 has decided not to use the compiled code. That can happen, for example, when running node with certain V8 flags. However, actively deleting something from the cache means that two Node.js processes running with different command-line flags but using the same WebAssembly cache will keep filling and erasing the cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tniessen that's a really good point. Do you see a way to isolate this deletion?
env->wasm_streaming_compilation_callback() | ||
->Call( | ||
env->context(), Undefined(env->isolate()), arraysize(args), args) | ||
.ToLocalChecked(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if this throws?
this allows user code to take full advantage of v8's wasm streaming api by caching previously compiled modules.
Fixes: #36671