Repository navigation
perf: vectorize Spark hash loops for arrays without nulls - #7687
mbutrovich wants to merge 2 commits into
Conversation
comphead
left a comment
There was a problem hiding this comment.
Thanks, the zipped loops and the up-front length check read well. I traced the recursive callers (the list, map and struct fallbacks, dictionary unpacking, and the batched list gather). Each one passes a buffer as long as its column, so the new check can't fire on a valid plan. One test point inline. I don't have x86 hardware either, so I can't answer the xxhash64 question.
| } | ||
|
|
||
| #[test] | ||
| fn test_hashes_buffer_length_mismatch_is_error() { |
There was a problem hiding this comment.
The check lives in the shared create_hashes_internal!, so this test and the one in murmur3.rs run the same code. test_non_canonical_nan_hashes_like_canonical_nan in murmur3.rs already checks both hashers in one test because they expand the same macros. Doing the same here would keep murmur3::tests private and drop length_mismatch_arrays as a cross-module helper.
There was a problem hiding this comment.
Thanks, merged into one test in murmur3.rs that runs both hashers, and murmur3::tests is private again.
|
Thanks for the feedback, @comphead! |
Which issue does this PR close?
Rationale for this change
The loops that hash fixed-width columns without nulls in Comet's murmur3 and xxhash64 index both the values and the hash buffer per row (
hash_array_primitive!). Insidecreate_murmur3_hashes, LLVM reloads the values pointer and checks bounds on every row, and reportsloop not vectorized: cannot identify array bounds. In the 1.2.0 jar,create_murmur3_hasheshas no vector multiply in either the amd64 or the aarch64libcomet.so. Murmur3 is the hash for shuffle hash partitioning (multi_partition.rs).What changes are included in this PR?
The loops for arrays without nulls iterate the hash buffer and the values together, so the primitive, float, boolean, interval, and small decimal loops can vectorize. With this change, the Int32 and Int64 murmur3 loops vectorize in a thin-LTO
libcometbuilt with-Ctarget-cpu=x86-64-v3and with-Ctarget-cpu=neoverse-n1. Each column's length is now checked against the hash buffer, because a zipped loop would skip rows instead of panicking.The loops for arrays with nulls are unchanged.
Benchmark results
These are local runs on an Apple M5 Max. They don't predict the Neoverse-N1 and x86-64-v3 builds that Comet releases. Both sides used
-Ctarget-cpu=nativeand thin LTO, and they alternated within one run. The aligned layout adds-C llvm-args=-align-all-functions=7 -C llvm-args=-align-all-nofallthru-blocks=7to both sides. xxhash64 stays scalar on ARM, so its bars say nothing about x86-64-v3. The datafusion-spark case doesn't reach the changed code.Could a reviewer with an x86 machine benchmark this against
main? I don't have x86 hardware, and the xxhash64 case is the open question: on x86-64-v3, LLVM vectorizes it by emulating 64-bit multiplies withvpmuludq, and only a benchmark shows whether that beats the scalar loop. On both sides:compatible/primitive_i64runs through datafusion-spark, which this PR doesn't change, so it shows the noise floor. The same run on a Neoverse-N1 machine with-Ctarget-cpu=neoverse-n1would cover the other release target. A shuffle-heavy TPC-H or TPC-DS run with an x86-64-v3 release jar would show the effect on shuffle hash partitioning.How are these changes tested?
The existing hash tests check the hash values.
test_hashes_buffer_length_mismatch_is_errorinmurmur3.rschecks the length check for both hashers.AI usage disclosure
I wrote this PR with help from Claude but understand and support the core approach, implementation, and test coverage.