Accept WebAssembly.Module values in the dynamic worker loader - #6997
Open
guybedford wants to merge 1 commit into
Open
Accept WebAssembly.Module values in the dynamic worker loader#6997guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
2 similar comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Merging this PR will not alter performance
Comparing Footnotes
|
A module in the worker loader modules bag may now be provided as a
WebAssembly.Module directly (e.g. obtained via a source phase import),
either as the module value itself or as { wasm: module }. The compiled
code is shared with the loaded worker via v8::CompiledWasmModule rather
than recompiling the wire bytes, in both the legacy and new module
registries. Inside the loaded worker the module can be imported with
import source, matching the ESM phase imports proposal semantics.
Includes jsg support for unwrapping v8::WasmModuleObject handles so
that jsg::V8Ref<v8::WasmModuleObject> can be used as a parameter and
struct field type, with rtti and TypeScript type updates.
guybedford
force-pushed
the
gbedford/wasm-module-serialization
branch
from
August 17, 2026 21:57
7112e10 to
caf8765
Compare
jasnell
reviewed
Aug 18, 2026
| KJ_SWITCH_ONEOF(wasm) { | ||
| KJ_CASE_ONEOF(bytes, kj::Array<const byte>) { | ||
| // Same as `data` above: copy out of the V8 BackingStore before going async. | ||
| bytes = kj::heapArray<const kj::byte>(bytes.asPtr()); |
Collaborator
There was a problem hiding this comment.
I know these are fine but they do require a double take to verify they are safe... at first glance it looks like bytes ends up dangling. Maybe worth expanding the comment more.
jasnell
approved these changes
Aug 18, 2026
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.
This implements support for passing compiled
WebAssembly.Moduleobjects into the dynamic worker loader modules bag, allowing compiled Wasm modules to be shared with loaded workers without recompilation.The motivating flow is source phase imports into dynamic workers:
What was implemented:
modulesbag accepts aWebAssembly.Moduleas a module value, or{ wasm: module }alongside the existing{ wasm: bytes }form.WorkerSource::WasmModulecarries an optionalv8::CompiledWasmModule; both the legacy and new module registries useFromCompiledModulewhen present (the new registry seeds its existing compile cache), so the loaded worker shares compiled code with zero recompilation. The loader and loaded worker are always in the same process, which is exactly the boundaryv8::CompiledWasmModulesupports; the module wire bytes remain available as the module body.jsg::V8Ref<v8::WasmModuleObject>is now unwrappable, with rtti and TypeScript type updates (Record<string, string | WebAssembly.Module | WorkerLoaderModule>).Test coverage: end-to-end loader tests (source phase import → loader →
import source+ default import in the child, against both module registries, covering both accepted forms).In future, dynamic
import()could work directly against these module objects as well, per the ESM Phase Imports proposal.