perf: speed up scaled decimal casts to double and float #7802
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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
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
comphead
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
i64for double andi32for 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
CometNativeCastSuitereported 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.