← Back to Pull requests

Keep Pyodide's compiled Wasm module alive across isolates #7706

Closed
unknown closed this pull request without merging on Oct 15, 2026 16:06 UTC
View on GitHub
unknown unknown commented on Oct 12, 2026 17:22 UTC
Author

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.wasm gone 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 a v8::CompiledWasmModule alive for its own lifetime and instantiates it in any isolate via FromCompiledModule. Compiled code bakes in its compile-time imports, which depend on wasm_esm_integration_builtins (#7685), so the holder keeps one module per setting and reuses only the matching one.

PyodideBundleManager owns one holder per loaded bundle version. registerPythonCommonModules takes it as a trailing optional argument and passes it to a new addBuiltinBundle(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 through registerPythonCommonModules with a shared PyodideBundleManager. 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 temporary Maybe lifetime error in the test; the lookup now stays alive through reader use. The rebased source 235faf7ef passed 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 on e70c9394cf, 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).

Diff: 429 lines (+321 / -108) across 5 files Reviewer: ryanking13 Review duration: 4244m
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
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.1% (MEDIUM) · Higher = larger blast radius
45.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.8% · Safe to merge
17.8%