module: DeserializeWasmModule should not assume synchronous WasmModuleCompilation::Finish
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Feature
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- javascript
- Bereich
- backend
Rechercherichtung
Start with DeserializeWasmModule in src/node_modules.cc and the Wasm translator in lib/internal/modules/esm/translators.js. Read the V8 Wasm API contract in include/v8-wasm.h and assess the proposed synchronous deserialization API against the async translation alternative. Done means Node and V8 agree on an approach that preserves synchronous ESM translation and handles cache misses without wasted compilation.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem
DeserializeWasmModule in src/node_modules.cc (introduced in #66191) deserializes cached WebAssembly modules via v8::WasmModuleCompilation:
WasmModuleCompilation compilation(options);
compilation.SetHasCompiledModuleBytes();
compilation.OnBytesReceived(wire.data(), wire.size());
compilation.Finish(
isolate,
[&](WasmStreaming::ModuleCachingInterface& cache) {
state->accepted = cache.SetCachedCompiledModuleBytes(code);
},
[state, isolate](std::variant<Local<WasmModuleObject>, Local<Value>> result) {
// When the cached code is accepted, V8 resolves synchronously within
// Finish(). Otherwise V8 falls back to compiling the wire bytes
// asynchronously; that result arrives later and is unused.
if (!state->in_finish) return;
if (auto* module = std::get_if<Local<WasmModuleObject>>(&result)) {
state->module.Reset(isolate, *module);
}
});
state->in_finish = false;
if (!state->accepted || state->module.IsEmpty()) return {};
return state->module.Get(isolate);
This currently relies on an undocumented implementation detail: v8::WasmModuleCompilation::Finish is documented in V8's include/v8-wasm.h as asynchronous ("This callback will also be called in foreground, but not necessarily within this call").
On the V8 side, we want to unconditionally defer all streaming/async completion callbacks from Finish() to a non-nestable foreground task rather than executing completion synchronously on the Finish() call stack. Doing so currently breaks parallel/test-compile-cache-wasm on V8's node-ci integration bot because DeserializeWasmModule assumes resolution_callback runs synchronously inside Finish().
As a secondary issue, using WasmModuleCompilation here also triggers a wasted asynchronous compilation of the wire bytes on every cache miss/rejection (whose result is later discarded when state->in_finish is false).
Proposed solutions
Since translators.get('wasm') in lib/internal/modules/esm/translators.js calls getWasmCompileCacheEntry(...) synchronously and falls back to synchronous new WebAssembly.Module(...), there are two clean ways forward:
- Add a dedicated synchronous deserialization API in V8 (e.g.
v8::WasmModuleObject::Deserialize(Isolate*, std::span<const uint8_t> wire_bytes, std::span<const uint8_t> serialized_bytes, const CompileOptions& options = {}), symmetric withWasmModuleObject::CompileandCompiledWasmModule::Serialize) and switchDeserializeWasmModuleinsrc/node_modules.ccto use it. This keeps Node's ESM Wasm translator synchronous, eliminates the wasted background compilation on cache rejection, and allows V8 to unconditionally deferWasmModuleCompilation::Finish. - Consume
WasmModuleCompilation::Finishasynchronously in Node (if the Wasm compile-cache lookup/translation path is changed to be async).
Option 1 looks simplest and cleanest for both Node.js and V8. Please let us know if that API shape works for Node.js, and we can add it to V8 first and then migrate v8/node + upstream nodejs/node.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 124k
- Forks
- 38k
- Ø Merge
- 4 T. 2 Std.
- Gemergte PRs (30 T.)
- 266
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nodejs/node
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 69/100
Maintainer antworten meist innerhalb von 1 Tag
-
fs: document readStream.start and readStream.endEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offendoc
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
nodejs/node#67848 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
doc: document the Buffer.prototype.*Slice() methodsEvtl. vergeben @AyushCipher hat das heute übernommen. Offendoc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
nodejs/node#67847 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
`styleText` fast path bypasses `options` and `options.validateStream` validationEvtl. vergeben @GBra-4-669 hat das vor 8 Tagen übernommen. Offenutil
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
riscv64
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
nodejs/node#67655 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
bug triage needed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 2 Tagen
-
[Resource]: PersephoneOffenresource-submission validation-passed
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
hesreallyhim/awesome-claude-code#3773 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 73/100
tabatkins/railroad-diagrams#129 ·
-
web: api() turns a null or object-valued error body into a TypeError or "[object Object]" and loses the statusEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
OCM: shares using the `embedded` protocol are rejected with "Missing sharedSecret in protocol"Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag