← Back to Pull requests

Use simdutf's bounded conversions in encodeInto() #8240

Closed
unknown closed this pull request without merging on Nov 06, 2026 02:11 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 17:56 UTC
Author

This follows up #8224, replacing findBestFit() in encodeInto() under the ENABLE_FAST_TEXTENCODER autogate 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 with findBestFit(). After #8224 that estimate still stopped short in two cases:

On x86, where char is 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), so findBestFit() 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.

  • simdutf reports a lone lead surrogate with three bytes left as OUTPUT_BUFFER_TOO_SMALL rather than SURROGATE, so that tail is finished with convert_utf16_to_utf8_with_replacement_safe.
  • encodeIntoMatchesTheStandard replaces the findBestFit() unit tests. It compares encodeInto() 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 past written is touched. It runs on both paths, and the default V8 path passes it too, so enabling the autogate no longer changes results.

    text-encoder-bench gains 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.

    Diff: 275 lines (+206 / -69) across 3 files Reviewer: nathanwhit Review duration: 495m
    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
    0.40
    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%
    60%
    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.336
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8240"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 39.6% (MEDIUM) · Higher = larger blast radius
    39.6%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.6% · Safe to merge
    15.6%