← Back to Pull requests

perf: speed up scaled decimal casts to double and float #7802

Open
unknown opened this pull request with 262 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 30, 2026 20:41 UTC
Author

Which issue does this PR close?

Part of #5128.

Rationale for this change

The existing exactness checks already guarantee that the coefficient fits in a smaller integer.

What changes are included in this PR?

Cast through i64 for double and i32 for float inside those bounds. Scale-2 casts with in-range coefficients were 3.44× and 3.82× faster, respectively. Rounding and the wide-value fallback are unchanged.

How are these changes tested?

Added both signs at and around 2²⁴ and 2⁵³ to the bitwise rounding test. Extended the cast benchmark to cover nonzero scale. The native expression tests passed. Spark’s CometNativeCastSuite reported 207 passed, 1 canceled and 8 ignored.

<details>
<summary>Criterion results</summary>

cargo bench --bench cast_numeric, main (07caef5f) vs this change, AMD EPYC Genoa, x86-64-v3. Rust 1.99.1. Median of four alternating runs per version.

| Case | main (µs) | PR (µs) | Speedup |
|---|---:|---:|---:|
| cast_decimal_scale_zero/decimal12_to_f32 | 43.06 | 41.92 | 1.03× |
| cast_decimal_scale_zero/decimal12_to_f32_nulls | 42.35 | 43.34 | 0.98× |
| cast_decimal_scale_zero/decimal18_to_f64 | 42.39 | 43.84 | 0.97× |
| cast_decimal_scale_zero/decimal18_to_f64_nulls | 43.58 | 42.68 | 1.02× |
| cast_decimal_scale_zero/decimal38_to_f64 | 45.23 | 45.48 | 0.99× |
| cast_decimal_scale_zero/decimal38_to_f64_nulls | 43.31 | 44.47 | 0.97× |
| cast_decimal_scaled/f32/exact | 56.20 | 14.70 | 3.82× |
| cast_decimal_scaled/f32/exact_dense_nulls | 57.86 | 13.84 | 4.18× |
| cast_decimal_scaled/f32/exact_nulls | 57.98 | 13.73 | 4.22× |
| cast_decimal_scaled/f32/mixed | 423.58 | 383.08 | 1.11× |
| cast_decimal_scaled/f32/wide | 1128.99 | 1138.21 | 0.99× |
| cast_decimal_scaled/f64/exact | 55.88 | 16.23 | 3.44× |
| cast_decimal_scaled/f64/exact_dense_nulls | 58.17 | 15.94 | 3.65× |
| cast_decimal_scaled/f64/exact_nulls | 55.85 | 15.85 | 3.52× |
| cast_decimal_scaled/f64/mixed | 451.52 | 426.06 | 1.06× |
| cast_decimal_scaled/f64/wide | 1140.18 | 1125.64 | 1.01× |

</details>

Drafted with OpenAI Codex.

Diff: 262 lines (+196 / -66) across 3 files Reviewer: comphead Review duration: 2993m
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 262 lines diff across 3 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
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
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.333
Real PR Conversation Timeline
1 comments
"Review active on #7802"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% 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.3% (MEDIUM) · Higher = larger blast radius
39.3%
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: 46.7% · Lower = rushed or shallow review
46.7%
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: 20.9% · Safe to merge
20.9%