Release owned non-ASCII ESM source once transcoded #8889
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.42) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 337 lines diff across 4 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.348
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8889"
general
weight: 0.35
ryanking13
In the new module registry, a bundle ESM module owns a copy of its UTF-8 source (
kj::Arc<OwnedAscii>). V8 has no UTF-8 string representation, so on first compile a non-ASCII source is transcoded to Latin-1 or UTF-16.encodeSource()took the Arc by rvalue reference and moved from it only on the ASCII path, so a non-ASCII module kept its UTF-8 original inEsModule::sourcefor its whole lifetime, next to the transcoded copy that V8 actually reads.a31c33693 released the original after transcoding; 47a1a051d switched owned sources to
kj::Arcand lost the release. ThegetEncodedSource()initializer now clearsEsModule::sourceonce encoding has succeeded, so an encoding failure still leaves the source for kj::Lazy's retry. Nothing else readsEsModule::source: V8 re-reads source text from the transcoded external string, bundle code cache keys are computed when the registry is built, builtin keys hash the encoded source, and startup snapshots work from compiledv8::Modules.new_module_registryis on by default from compat date 2026-11-17. esbuild (and so Wrangler) escapes non-ASCII by default, so this mostly affects bundles from other tools and unbundled uploads.Measurements
Native arm64 opt builds of main and of this change. One Worker whose main module is a large block comment containing non-ASCII text, at compat date 2026-11-20, measured 2 s after its first request. Three runs each, alternating order; every run gave the same numbers.
| Module | Live large allocations, main → this PR | RSS, main → this PR |
|---|---|---|
| 4 MB ASCII | 8.0 → 8.0 MB | 44 → 44 MB |
| 4 MB with
é(Latin-1) | 10.7 → 6.7 MB | 46 → 42 MB || 4 MB with
€(UTF-16) | 12.1 → 8.0 MB | 48 → 44 MB || 32 MB ASCII | 64.0 → 64.0 MB | 100 → 100 MB |
| 32 MB with
é(Latin-1) | 85.4 → 53.4 MB | 121 → 89 MB || 32 MB with
€(UTF-16) | 96.2 → 64.1 MB | 132 → 100 MB |Each non-ASCII module saves its UTF-8 size; ASCII modules are unaffected. The ASCII rows' live memory is the config message, which standalone workerd keeps, plus the registry's copy of the module. "Live large allocations" is vmmap's non-empty
MALLOC_LARGE. RSS was measured withMallocLargeCache=0; macOS malloc otherwise keeps freed large blocks resident, and RSS reads 196 MB for every 32 MB variant.Testing
A new
modules-new-testcase builds ASCII, Latin-1 and UTF-16 bundle modules from buffers with a countingArrayDisposer, resolves each, and checks that both non-ASCII originals are freed while the registry is alive and the ASCII one is not. It fails without the fix.modules-new-testand every new-module-registry, startup-snapshot and NMR extensions.wd-testpass in all variants.