← Back to Pull requests

Centralize JavaScript compilation and cache builtin modules #8184

Closed
unknown closed this pull request without merging on Nov 04, 2026 15:34 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 12:49 UTC
Author

JavaScript compilation should reuse cached bytecode consistently for application code and runtime-provided modules, regardless of which module registry loads them. This extends the process-wide cache introduced in #7664 to builtin ES modules and CommonJS evaluation functions, and makes embedded builtin bytecode available in both registries.

Previously, the registries and script helpers selected caches at separate compilation sites. Legacy builtins only consumed embedded bytecode, so a builtin without an embedded cache compiled from source in every isolate. New-registry builtins used a separate per-definition slot, and constructing builtin modules from Cap'n Proto bundles discarded their embedded compileCache. CommonJS evaluation functions bypassed the process-wide store. These gaps account for the explicit Pyodide cache plumbing in #8181: sharing the same JavaScript source did not imply sharing its compilation work.

Introduce a common JSG compilation boundary for ES modules, classic scripts, and CommonJS functions. Both registries supply source, origin, source identity, and available cache metadata; the compilation layer selects embedded bytecode, the process-wide store, or the new registry's definition-local fallback slot. Hint production bypasses bytecode caches, and hint consumption remains available without an applicable cache. The runtime cache invokes a synchronous compilation callback on both hits and misses, supplying V8's source and compilation options. A hit still calls V8's compilation API to deserialize bytecode. The cache owns lookup, rejection handling, producer election, and deferred serialization independently of the V8 operation.

Cache keys distinguish the exact source representation and compilation shape, including Latin-1 versus UTF-16 and functions with or without a context extension. Function caches bind to the receiving isolate's context. Embedded caches take precedence over runtime caching and work without an installed store; both registries report embedded-cache hits and rejections consistently. The definition-local fallback checks deserialization rejection after compilation and replaces rejected data without discarding an entry another replica has already replaced. A slot generation identifies the rejected entry across the read-to-write lock transition, even if an allocator reuses its address. Snapshot preparation can consume that slot but never generates bytecode.

Runtime production retains the existing startup window and serializes after top-level evaluation, capturing functions compiled lazily during startup. Request-time compilation consumes existing process-wide entries, but misses do not produce new ones. Worker bundle lookups remain prepared before startup CPU accounting; builtin and CommonJS lookups happen at compilation time, and new-registry builtin hashes are memoized per definition. The store's existing byte limits and eviction policy apply to the additional entries. Internal non-module script helpers keep their existing uncached behavior. Build-time caches remain useful for cold processes and isolates without a store; this does not enable Bazel cache generation for additional libraries.

Diff: 411 lines (+308 / -103) across 5 files Reviewer: ryanking13 Review duration: 1604m
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 · 411 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.360
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8184"
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: 44.9% (MEDIUM) · Higher = larger blast radius
44.9%
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.7% · Safe to merge
17.7%