perf: fast-path scalar arithmetic, comparisons, and common builtin operations #1255
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
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.347
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1255"
general
weight: 0.35
davidhewitt
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:
crates/monty/src/bytecode/vm/binary.rs): Direct fast-path integer arithmetic (+,-,*,%) and string concatenation (+,+=) bypassing generic method dispatch.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 existinglistandtupleinstances 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) avoidingFromArgsparsing.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 intimedelta.days. Includes integration tests incrates/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.==,!=,<,<=,>,>=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.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. -->