← Back to Pull requests

Convert UTF-16 to UTF-8 with simdutf in rust::String::lossy #8586

Closed
unknown closed this pull request without merging on Nov 19, 2026 07:30 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 05:29 UTC
Author

Rust JSG copies every two-byte String argument into a Rust String with rust::String::lossy, which called std's String::from_utf16_lossy. That starts from a len / 2 capacity and regrows as it pushes each char, so a 16-unit CJK string took 229 ns in Rust against 137 ns in C++, and long strings were no faster than C++.

In this patch the cxx fork computes the exact UTF-8 length with simdutf and converts into a Vec of that size, as from_latin1 already does. simdutf's with_replacement functions turn each unpaired surrogate into U+FFFD, the same output as from_utf16_lossy. Two new jsg-tests check this against from_utf16_lossy: one with random two-byte strings dense in lone and paired surrogates, and one that sweeps a single surrogate or pair across every position of an otherwise clean string.

| string/in (Rust) | before | after | speedup | C++ |
|---|---:|---:|---:|---:|
| utf16/16 | 229 ns | 159 ns | 1.4x | 137 ns |
| utf16/1024 | 3.14 µs | 0.45 µs | 6.9x | 3.58 µs |
| utf16/65536 | 192 µs | 19.7 µs | 9.7x | 222 µs |

Measured with bench-jsg on Linux x86-64, linked statically, CPU time per call, median of 10 runs.

Diff: 143 lines (+107 / -36) across 1 files Reviewer: littledivy Review duration: 1560m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.38) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.38 · 143 lines diff across 1 files
0.38
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.297
Shallow Review Depth shallow_review_depth
0.289
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #8586"
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: 37.7% (MEDIUM) · Higher = larger blast radius
37.7%
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: 16.3% · Safe to merge
16.3%