← Back to Pull requests

Avoid allocations for short string operations #1433

Closed
unknown closed this pull request without merging on Nov 26, 2026 10:23 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 09:57 UTC
Author

Summary

  • Borrow inline text without revalidating UTF-8. Construction and snapshot deserialization populate the payload from valid Rust text.

  • Build concatenation and repetition results of up to 15 UTF-8 bytes without a temporary heap allocation. Reuse the ASCII status of the operands.

  • Deserialize inline snapshot strings directly from decoded text, avoiding a temporary String allocation.
  • Benchmarks

    Local Apple Silicon release builds, measured in 10 alternating before/after pairs.

    String operations compare 78cb6ac8 (upstream base) with d1b68fb8 (the first PR commit).
    Timings include the Python loop, with 500,000 iterations per run.

    | Workload | Base | PR | Change in elapsed time |
    | --- | ---: | ---: | ---: |
    | Short ASCII concatenation | 34.5 ns | 25.2 ns | −27% |
    | Short Unicode concatenation | 33.9 ns | 24.4 ns | −28% |
    | Short ASCII repetition | 39.1 ns | 30.7 ns | −21% |
    | Short Unicode repetition | 39.4 ns | 30.7 ns | −22% |
    | Dict lookup with an inline string key | 40.1 ns | 38.1 ns | −4% |
    | 48-byte concatenation | 41.8 ns | 39.7 ns | −5% |
    | Integer addition control | 13.2 ns | 13.3 ns | Flat |

    Allocation counts confirmed one fewer heap allocation per short concatenation or repetition.

    Dump loads compare d1b68fb8 with bb7aa67b, which adds the deserialization change.
    Both builds loaded the same snapshot bytes.

    | Snapshot | Before | After | Change in elapsed time |
    | --- | ---: | ---: | ---: |
    | 50,000 inline string entries | 1.10 ms | 0.75 ms | −32% |
    | Checked-in v17 fixture | 194 µs | 194 µs | Flat |

    Tests

  • cargo test -p monty --lib --test string_identity --test dump_compat

  • cargo run -p monty-datatest -- str__ --skip run_test_cases_cpython

  • make format-rs and make lint-rs
  • Diff: 219 lines (+164 / -55) across 2 files Reviewer: davidhewitt Review duration: 1466m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 219 lines diff across 2 files
    0.37
    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.323
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1433"
    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: 36.7% (MEDIUM) · Higher = larger blast radius
    36.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: 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: 14.5% · Safe to merge
    14.5%
    Repository