← Back to Pull requests

Release owned non-ASCII ESM source once transcoded #8889

Closed
unknown closed this pull request without merging on Nov 25, 2026 03:08 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 01:07 UTC
Author

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 in EsModule::source for its whole lifetime, next to the transcoded copy that V8 actually reads.

a31c33693 released the original after transcoding; 47a1a051d switched owned sources to kj::Arc and lost the release. The getEncodedSource() initializer now clears EsModule::source once encoding has succeeded, so an encoding failure still leaves the source for kj::Lazy's retry. Nothing else reads EsModule::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 compiled v8::Modules.

new_module_registry is 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 with MallocLargeCache=0; macOS malloc otherwise keeps freed large blocks resident, and RSS reads 196 MB for every 32 MB variant.

Testing

A new modules-new-test case builds ASCII, Latin-1 and UTF-16 bundle modules from buffers with a counting ArrayDisposer, 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-test and every new-module-registry, startup-snapshot and NMR extensions .wd-test pass in all variants.

Diff: 337 lines (+252 / -85) across 4 files Reviewer: ryanking13 Review duration: 120m
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
0.42
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%
56%
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.348
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8889"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% 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: 42.2% (MEDIUM) · Higher = larger blast radius
42.2%
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: 56.8% · Lower = rushed or shallow review
56.8%
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: 18.3% · Safe to merge
18.3%