Keep Pyodide's compiled Wasm module alive across isolates #7706
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 429 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.363
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #7706"
general
weight: 0.35
ryanking13
V8 shares a compiled Wasm module between isolates in a process, but only while some isolate still references it. Python isolates are rare per machine, so the next one usually finds
pyodide.asm.wasmgone from V8's cache and compiles it again. We measured 100 to 150 ms of CPU per Python isolate, nearly all of it lazy function compiles.This adds
jsg::CompiledWasmModuleHolder, which keeps av8::CompiledWasmModulealive for its own lifetime and instantiates it in any isolate viaFromCompiledModule. Compiled code bakes in its compile-time imports, which depend onwasm_esm_integration_builtins(#7685), so the holder keeps one module per setting and reuses only the matching one.PyodideBundleManagerowns one holder per loaded bundle version.registerPythonCommonModulestakes it as a trailing optional argument and passes it to a newaddBuiltinBundle(bundle, holder)overload in the old module registry. Existing callers compile unchanged. The new module registry is not touched.Memory cost: the wire bytes (about 10 MB per release) plus generated code, per builtins setting in use, for the process lifetime. Pyodide releases come from a fixed set of compat flags, so this is bounded.
modules-new-test.c++checks the holder directly across successive isolates.pyodide/wasm-module-test.c++additionally registers a minimal bundle throughregisterPythonCommonModuleswith a sharedPyodideBundleManager. It destroys each registry and isolate before the next load and checks one compilation followed by one cache instantiation for each Wasm builtins setting. Both variants passed five first attempts on Linux, Windows and ASan (30/30); disconnecting the holder from registration makes the reuse assertions fail. Strict CI and negative control. ASan caught a temporaryMaybelifetime error in the test; the lookup now stays alive through reader use. The rebased source235faf7efpassed a fresh five-attempt Linux/Windows/ASan audit on 2026-10-15: 30/30 explicit regression passes, with no failures, skips, or retries (rebased audit). Fresh full PR CI is running one70c9394cf, rebased onto main after #7760. Pyodide's dynamic libraries (UnsafeEval::newWasmModule) are unchanged.The rebase retains the timer queue move repair now present in main.
🤖 Generated with Claude Code
The JSG invariants document that every compat flag changing Wasm compilation options or compile-time imports must extend the holder slot key/storage and the reuse tests.
CI found separate termination-injection and HTTP test flakes, repaired in #7760. A downstream tracing timeout is tracked separately in draft #7761, with five-run CI validation (audit). These test repairs are kept out of this feature PR. Shepherd records any recognized-flake retries alongside their original failures.
The Pyodide code and regressions are unchanged by the latest rebase. Draft #7761 passed all 30 release/debug/ASan audit suites. Draft #7762 passed all 90 ARM debug, x64 debug, and ASan audit suites on their first attempts (audit).