mbutrovich opened a new pull request, #11427: URL: https://github.com/apache/arrow-rs/pull/11427
# Which issue does this PR close? - Part of #11421. # Rationale for this change #11421 proposes replacing the per-row division in `div` and `rem` by a scalar with a precomputed reciprocal. The kernel PRs need benchmarks on `main` to report before and after numbers. Today [`arithmetic_kernels`](https://github.com/apache/arrow-rs/blob/c7f60c612bd16ca5485cc9acddfd216c10ea9765/arrow/benches/arithmetic_kernels.rs#L26-L74) covers only `Float32`, and [`decimal_arithmetic`](https://github.com/apache/arrow-rs/blob/c7f60c612bd16ca5485cc9acddfd216c10ea9765/arrow-arith/benches/decimal_arithmetic.rs#L39-L56) covers only `add` and `sub`. # What changes are included in this PR? This PR adds a benchmark for integers and extends the decimal one. All values come from a fixed seed, and each array is divided by a `Scalar`, so the divisor is the same for every row. - `integer_division` is a new benchmark. It runs `div` and `rem` on 8192 random `Int32`, `UInt32`, `Int64` and `UInt64` values, divided by 13 and by 16. A precomputed divisor can replace division by a power of two with a shift or mask, so 16 is a separate case. - `decimal_arithmetic` gains `div` and `rem` by a scalar for `Decimal128` and `Decimal256`. The values have scale 10 and the divisors have scale 2. For each type there are three cases: values that fit in half the type's width after `div` scales them, wider values, and a divisor wider than half the type's width. `Decimal32` and `Decimal64` divide with the same instructions as `Int32` and `Int64`, so they aren't repeated. Both benchmarks run one case per type and operation on an array where every fifth value is null, because [`try_unary`](https://github.com/apache/arrow-rs/blob/c7f60c612bd16ca5485cc9acddfd216c10ea9765/arrow-array/src/array/primitive_array.rs#L1017-L1020) visits only the valid values when there are nulls. Both also run `div` on 1, 16 and 128 values. Building a reciprocal costs more than one division, so these cases show where the per-array setup outweighs the per-value savings. `arrow-arith` gains `rand` as a dev-dependency, with the same features as `arrow-ord`. # Are these changes tested? This PR only adds benchmarks. # Are there any significant user-facing changes? No. ## AI Disclosure I wrote this PR with help from Claude but understand and support the core approach, implementation, and test coverage. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
