mbutrovich opened a new issue, #27974:
URL: https://github.com/apache/datafusion/issues/27974

   ## Is your feature request related to a problem or challenge?
   
   #27559 hashes primitive arrays with nulls 64 rows at a time and picks a loop 
for each chunk by its count of valid rows 
([`count_ones`](https://github.com/apache/datafusion/blob/c925aff1c7025c9ae11633b63a4058c57eba45b8/datafusion/common/src/hash_utils.rs#L371)).
 With the default x86-64 target there is no POPCNT, so that count is a 
16-instruction sequence on every chunk 
([listing](https://github.com/apache/datafusion/pull/27559#discussion_r4645790730)).
 At 99% random nulls the chunks hold almost no valid rows, so the count is a 
large share of the work. Those cases are 1.10x to 1.32x slower than before 
#27559 on a Xeon Platinum 8581C 
([run](https://github.com/apache/datafusion/pull/27559#issuecomment-7045011123)).
 With `x86-64-v3` they are within 6% 
([run](https://github.com/apache/datafusion/pull/27559#issuecomment-7045017844)).
   
   ## Describe the solution you'd like
   
   Skip all-null chunks before counting, as @jayzhan211 suggested in 
https://github.com/apache/datafusion/pull/27559#discussion_r4727425981:
   
   ```rust
   if valid == 0 {
       continue;
   }
   ```
   
   At 99% random nulls a chunk is all null with probability 0.99^64, or 53%. 
For an all-null chunk, the per-row loop in `hash_prim_valid` already exits on 
its first test, so the change saves only the count. It should help only on 
targets without POPCNT, and only at null densities where many chunks are all 
null. At 90% random nulls, 0.1% of chunks are.
   
   The new branch is unpredictable at 99% nulls. It tests the same condition as 
the loop guard it runs ahead of, so it should not add many mispredictions, but 
the benchmark has to show that.
   
   To evaluate it, run `with_hashes` on the bot with the default x86-64 target 
and with `x86-64-v3`, and on Neoverse-V2. The `99% nulls` cases should gain on 
the default x86-64 target. The `no nulls` cases don't reach this code and show 
the noise of the run.
   
   ## Describe alternatives you've considered
   
   A gate on the array's `null_count` that keeps the per-row loop for sparse 
arrays. @jayzhan211 measured it as 7% to 24% slower than #27559 at 25% to 50% 
nulls on an M4 Pro 
([comment](https://github.com/apache/datafusion/pull/27559#discussion_r4727425981)).
   
   ## Additional context
   
   None.
   


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