← Back to Pull requests

perf: fast-path scalar arithmetic, comparisons, and common builtin operations #1255

Closed
unknown closed this pull request without merging on Nov 16, 2026 13:22 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 22:10 UTC
Author

Summary

Extracted from #1035 as requested in review comments to separate unrelated performance improvements from class inheritance.

This PR introduces targeted fast-paths for common scalar and builtin operations without altering Python semantics or resource tracking:

  • Scalar Arithmetic & String Concat (crates/monty/src/bytecode/vm/binary.rs): Direct fast-path integer arithmetic (+, -, *, %) and string concatenation (+, +=) bypassing generic method dispatch.

  • Scalar Comparisons (crates/monty/src/bytecode/vm/compare.rs): Fast-paths for (int, int) and (bool, bool) in equality and ordering comparisons (==, !=, <, <=, >, >=).

  • sorted() Builtin (crates/monty/src/builtins/sorted.rs): Direct-clone items from existing list and tuple instances with preflight and deadline checks, bypassing iterator allocation.

  • str.replace & str.encode (crates/monty/src/types/str.rs): Fast-path 2-argument interned string replacements and common default/interned encodings (utf-8, ascii) avoiding FromArgs parsing.

  • strftime & timedelta.days (crates/monty/src/types/date.rs, crates/monty/src/types/datetime.rs, crates/monty/src/types/timedelta.rs): Fast-paths for standard formats (%Y-%m, %Y-%m-%d, etc.) on naive instances and direct day calculation in timedelta.days. Includes integration tests in crates/monty/tests/datetime_format.rs.
  • <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Adds fast-paths for common scalar comparisons and for sorted() on lists and tuples without changing Python semantics or resource tracking.

  • Short-circuits ==, !=, <, <=, >, >= on ints and bools before generic method dispatch.

  • sorted() clones items directly from existing lists and tuples while preserving the same time and memory limit checks.

  • Extends resource-limit tests to cover the new sorted() copy path and isolates the deadline check to the sorting comparison loop.
  • <sup>Written for commit 0eb4ca627c68124d49923450f4289a67b7a4c4f7. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1255?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 330 lines (+247 / -83) across 4 files Reviewer: davidhewitt Review duration: 15312m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 330 lines diff across 4 files
    0.42
    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.347
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1255"
    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: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    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: 16.6% · Safe to merge
    16.6%
    Repository