module: DeserializeWasmModule should not assume synchronous WasmModuleCompilation::Finish
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- javascript
- 領域
- backend
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- JavaScript
- スター
- 124k
- フォーク
- 38k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 266
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nodejs/node のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
メンテナーはふだん 1 日以内に返信
-
fs: document readStream.start and readStream.end対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンdoc
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
nodejs/node#67848 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
doc: document the Buffer.prototype.*Slice() methods対応中かも @AyushCipher が今日担当しました。 オープンdoc
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
nodejs/node#67847 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
`styleText` fast path bypasses `options` and `options.validateStream` validation対応中かも @GBra-4-669 が 8 日前に担当しました。 オープンutil
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
riscv64
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nodejs/node#67655 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug triage needed
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
resource-submission validation-passed
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
hesreallyhim/awesome-claude-code#3773 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 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 status対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信