mbutrovich commented on PR #7691: URL: https://github.com/apache/datafusion-comet/pull/7691#issuecomment-7019216463
The 99% nulls case is 33x faster because the loop this PR replaces ([`hash_array_primitive!`](https://github.com/apache/datafusion-comet/blob/d187e6823f9052e7331e8a810b08a1202debb91c/native/spark-expr/src/hash_funcs/utils.rs#L108-L112)) pays for every row, null or not. In a thin-LTO aarch64 build of #7687, a null row runs 18 instructions in `create_murmur3_hashes`. Four of them reload the null buffer's fields from the array on every row, and two more bounds-check the row index against the null buffer's length. Then it loads a validity byte, shifts, and tests the bit. The `hash_nulls` input at 99% has 80 valid rows out of 8192, and 70 of its 128 chunks are all null. Splitting the measured times into a cost per row and a cost per valid row gives about 0.51 ns per row plus 4.6 ns per valid row before this PR. That's 4.16 us of null checks and 0.37 us of hashing at 99%. This PR pays about 0.44 ns per 64-row chunk plus 1.0 ns per valid row, or 0.06 us and 0.08 us. Those are two data points fitted to two parameters, so the disassembly is what supports the split. apache/datafusion#27559 lost at 99% nulls with the same chunk loop ([Neoverse-V2](https://github.com/apache/datafusion/pull/27559#issuecomment-6988997390), [Xeon](https://github.com/apache/datafusion/pull/27559#issuecomment-6989016305)) because its baseline was different. DataFusion's loop iterates `valid_indices()` ([`hash_utils.rs`](https://github.com/apache/datafusion/blob/bc598ee288f1ad22c5ab0c7ccce93caf1f5748d6/datafusion/common/src/hash_utils.rs#L314-L325)), which walks the bitmap a word at a time and jumps to each valid row. Its cost already grows with words and valid rows, not with all rows, so the chunk loop's overhead per chunk decides the comparison there. So most of the gain at high null rates here comes from no longer checking every row. A `valid_indices()` loop would capture much of it too, because its cost grows the same way, but I haven't measured that. The 64-row chunks add the gains at low null rates, where a dense chunk runs the vectorized loop from #7687. -- 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]
