module: DeserializeWasmModule should not assume synchronous WasmModuleCompilation::Finish
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- backend
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- JavaScript
- Estrellas
- 124k
- Forks
- 38k
- Merge medio
- 4 d 2 h
- PR fusionados (30 d)
- 266
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nodejs/node
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
Los mantenedores suelen responder en 1 día
-
fs: document readStream.start and readStream.endPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodoc
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
nodejs/node#67848 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
doc: document the Buffer.prototype.*Slice() methodsPosiblemente ocupada @AyushCipher la tomó hoy. Abiertodoc
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
nodejs/node#67847 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
`styleText` fast path bypasses `options` and `options.validateStream` validationPosiblemente ocupada @GBra-4-669 la tomó hace 8 días. Abiertoutil
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
riscv64
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
nodejs/node#67655 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de nodejs/node
Issues similares
-
bug triage needed
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
[Resource]: PersephoneAbiertoresource-submission validation-passed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
hesreallyhim/awesome-claude-code#3773 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 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 statusPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
OCM: shares using the `embedded` protocol are rejected with "Missing sharedSecret in protocol"Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día