comphead opened a new pull request, #7658:
URL: https://github.com/apache/datafusion-comet/pull/7658

   ## Which issue does this PR close?
   
   No issue. Found while profiling TPC-H Q1 at SF10. `CheckOverflow` wraps 
every decimal `+ - *` there, and its no-overflow scan took about 5% of the 
native CPU samples.
   
   ## Rationale for this change
   
   Optimize existing expression. The no-overflow check iterated `Option`s with 
`.iter().flatten().all()`. That reads the null bitmap for every slot and 
branches on every value, so the loop does not unroll.
   
   ## What changes are included in this PR?
   
   - When the array has no nulls, scan the values buffer directly. Shifting by 
the precision's minimum turns the two bounds checks into one unsigned 
comparison per value. There is no branch inside each 64-value chunk, and the 
scan still stops at the first chunk that holds an overflow. Arrays with nulls 
keep the existing scan.
   - Benchmark: add `no overflow, dense nulls` and `ansi no overflow, with 
nulls` shapes.
   - Expression audit: record the tuning pass under `CheckOverflow`.
   
   ## How are these changes tested?
   
   Existing tests cover the no-null path for positive and negative overflow, 
the precision boundary, and ANSI errors. A new test covers an overflow past the 
first chunk and a sliced array with a non-zero offset.
   
   Criterion, `cargo bench --bench check_overflow -- --baseline main`, 8192 
rows, Apple M-series:
   
   | Shape | main | this PR | change |
   |---|---|---|---|
   | no overflow | 4.354 µs | 3.039 µs | −30.1% |
   | no overflow, with nulls | 4.807 µs | 4.758 µs | −1.2% |
   | no overflow, dense nulls | 3.990 µs | 3.884 µs | −0.9% |
   | sparse overflow | 4.315 µs | 4.280 µs | −0.6% |
   | dense overflow | 7.614 µs | 7.621 µs | −0.1% (p = 0.50) |
   | ansi no overflow | 4.405 µs | 3.028 µs | −31.1% |
   | ansi no overflow, with nulls | 4.872 µs | 4.747 µs | −2.7% |
   
   The machine was shared (load average about 4.5), so I took several samples. 
The two no-null shapes were 29% to 31% faster in every sample. Without 
`#[inline]` on the helper, `dense nulls` read +1.6% to +2.3% in three samples. 
With it, that shape and every other unchanged shape stayed within −2.7% to 
−0.1%.
   


-- 
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]

Reply via email to