Use simdutf's bounded conversions in encodeInto() #8240
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 275 lines diff across 3 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.336
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8240"
general
weight: 0.35
nathanwhit
This follows up #8224, replacing
findBestFit()inencodeInto()under theENABLE_FAST_TEXTENCODERautogate with simdutf's bounded conversions.simdutf's fast conversions have no output limit, so
encodeInto()first estimated how much of the input fits in the destination withfindBestFit(). After #8224 that estimate still stopped short in two cases:On x86, where
charis signed, a Latin-1 character such asécounted as three bytes.'é'.repeat(10)into 2 bytes read nothing, so a caller encoding in a loop made no progress.With five bytes left, a surrogate pair counted as six, and the character after it was dropped.
simdutf can now convert into a bounded destination and report how much it read (
convert_latin1_to_utf8_safe_with_details,convert_utf16_to_utf8_safe_with_details), sofindBestFit()is removed. Around those conversions:When the destination can hold any encoding of the input, the unbounded conversion is used, which is faster for short strings.
From the first lone surrogate on, the input is converted from one well-formed copy. simdutf's replacing conversions restart at each lone surrogate, which is about ten times slower when they are dense.
OUTPUT_BUFFER_TOO_SMALLrather thanSURROGATE, so that tail is finished withconvert_utf16_to_utf8_with_replacement_safe.encodeIntoMatchesTheStandardreplaces thefindBestFit()unit tests. It comparesencodeInto()with the Encoding Standard at every buffer size, across Latin-1, two-byte, emoji, mixed and lone-surrogate inputs at lengths converted in one piece and in several, and checks that nothing pastwrittenis touched. It runs on both paths, and the default V8 path passes it too, so enabling the autogate no longer changes results.text-encoder-benchgains half-sized destinations and emoji, mixed and lone-surrogate inputs. Against #8224 in an optimized build with all autogates,encodeInto()takes 0.66-0.94x the time when the destination is too small, and is level otherwise.Compatibility: no compatibility flag. Only the autogated path changes, and it now matches the default path at every buffer size.