andygrove opened a new pull request, #3619: URL: https://github.com/apache/datafusion-comet/pull/3619
## Summary - Replace the 4-node expression tree (`Cast(Decimal256→Decimal128, BinaryExpr(op, Cast(Decimal128→Decimal256, left), Cast(Decimal128→Decimal256, right)))`) used for Decimal128 add/sub/mul that may overflow with a single fused `WideDecimalBinaryExpr` that performs i256 register arithmetic directly - Reduces per-batch allocation from 4 intermediate arrays (3 Decimal256 @ 32 bytes/elem + 1 Decimal128 @ 16 bytes/elem = 112 bytes/elem) to 1 output array (16 bytes/elem) - Add criterion benchmark comparing old vs fused approach ### Benchmark results (8192 element batches) | Case | Old | Fused | Speedup | |------|-----|-------|---------| | add (same scale) | 171 µs | 57 µs | **3.0x** | | add (diff scale) | 173 µs | 57 µs | **3.0x** | | multiply | 361 µs | 305 µs | **1.2x** | | subtract | 173 µs | 58 µs | **3.0x** | ### How it works `WideDecimalBinaryExpr` evaluates left/right children, performs add/sub/mul using `i256` intermediates via `arrow::compute::kernels::arity::try_binary`, applies scale adjustment with HALF_UP rounding, checks precision bounds, and outputs a single `Decimal128` array. Follows the same pattern as `decimal_div` in `div.rs`. Overflow handling matches existing behavior: - **Ansi mode**: returns `ArrowError::ComputeError` - **Legacy/Try mode**: uses `i128::MAX` sentinel + `null_if_overflow_precision` ## Test plan - [x] 11 new Rust unit tests (add/sub/mul same/different scales, HALF_UP rounding, overflow in both modes, null propagation, edge cases) - [x] `cargo clippy --all-targets --workspace -- -D warnings` passes - [x] `cargo test` passes - [ ] Existing JVM tests (`CometExpressionSuite`) pass unchanged -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
