This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-11343-67bc67ed9f8733680fc5bcb4583415071b7ee6cf in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
commit 934e16ec8513fe8c1c8a7670f3741070a4c4781d Author: Kosta Tarasov <[email protected]> AuthorDate: Mon Oct 5 22:14:27 2026 +0000 Add focused float-to-decimal cast benchmarks (#11343) # Which issue does this PR close? Part of #10795. Adds benchmark coverage ahead of #11302. # Rationale for this change The existing float-to-decimal benchmarks cover safe Float64-to-Decimal128 casts with valid and non-finite inputs. They do not isolate Float32 conversion, successful strict casts, Decimal256 conversion, or target-precision overflow, paths affected by sharing checked float-to-decimal conversion between Arrow and Variant in #11302. # What changes are included in this PR? Add five benchmarks selected for distinct conversion paths: - Float32 to Decimal32 in safe and strict mode. - Float64 to Decimal128 in strict mode, complementing the existing safe case. - Float64 to Decimal256 with a negative scale, exercising its separate float-to-i256 conversion. - Precision overflow in safe mode, combining direct and rounding-induced overflow while processing the whole array. Fixtures contain 8192 rows with approximately 10% nulls. Fixture construction runs outside the timed loop. Use the existing `add_benchmark` and individual `bench_function` calls, following #11313. # Are these changes tested? Validation before removing the fixture assertions: - All five benchmark smoke cases pass on upstream main (`26de48deaf`) and #11302 (`15aeeb8098`). - `cargo +1.98.1 fmt --all -- --check`. - `cargo +1.98.1 clippy -p arrow --bench cast_kernels --features test_utils --no-deps -- -D warnings` passes, with the existing unknown `clippy::assert_is_empty` lint warning. Checking dependencies also encounters an existing `clippy::chunks_exact_to_as_chunks` lint in `arrow-row`. - Ran the same benchmarks on main and #11302 using Rust 1.98.1, identical dependencies, and CPU affinity. Each revision was measured twice in main / PR / PR / main order, with 50 samples, a one-second warmup, and a two-second measurement per case. After removing the fixture assertions, `cargo +1.98.1 fmt --all -- --check` and `git diff --check` pass. A fresh benchmark compile check was blocked by the local disk quota. # Are there any user-facing changes? No. Benchmark additions only. # AI usage Developed with assistance from OpenAI Codex for the benchmarks, validation, and PR description. --- arrow/benches/cast_kernels.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/arrow/benches/cast_kernels.rs b/arrow/benches/cast_kernels.rs index 1bda28b51a..f29bcca011 100644 --- a/arrow/benches/cast_kernels.rs +++ b/arrow/benches/cast_kernels.rs @@ -800,6 +800,49 @@ fn add_benchmark(c: &mut Criterion) { DataType::Decimal32(9, -1), &[true], ); + + // Choose distinct conversion paths, not every source/destination pair. + let float32: ArrayRef = Arc::new(create_primitive_array_range::<Float32Type>( + ROWS, + 0.1, + -9999.0..9999.0, + )); + bench( + "cast float32 to decimal32(7, 2) 8192 valid", + float32, + DataType::Decimal32(7, 2), + &[true, false], + ); + let float64: ArrayRef = Arc::new(create_primitive_array_range::<Float64Type>( + ROWS, + 0.1, + -9999.0..9999.0, + )); + // Safe Float64 -> Decimal128 and non-finite inputs are already covered above. + bench( + "cast float64 to decimal128(20, 3) 8192 valid", + float64.clone(), + DataType::Decimal128(20, 3), + &[false], + ); + // Decimal256 uses a separate float-to-i256 conversion implementation. + bench( + "cast float64 to decimal256(40, -2) 8192 scale down", + float64, + DataType::Decimal256(40, -2), + &[true], + ); + // Direct and rounding-induced overflow share the precision-failure path. + // The existing non-finite benchmark already covers native conversion failure. + let samples = [1000.0, -1000.0, 999.75, -999.75]; + let mut builder = Float64Builder::with_capacity(ROWS); + let overflow = build_array_with_samples!(builder, ROWS, 0.1, samples); + bench( + "cast float64 to decimal64(3, 0) 8192 precision overflow", + overflow, + DataType::Decimal64(3, 0), + &[true], + ); } criterion_group!(benches, add_benchmark);
