Convert UTF-16 to UTF-8 with simdutf in rust::String::lossy #8586
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
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.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
littledivy
Rust JSG copies every two-byte String argument into a Rust
Stringwithrust::String::lossy, which called std'sString::from_utf16_lossy. That starts from alen / 2capacity 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
Vecof that size, asfrom_latin1already does. simdutf'swith_replacementfunctions turn each unpaired surrogate into U+FFFD, the same output asfrom_utf16_lossy. Two new jsg-tests check this againstfrom_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.