From 2864ded0c531a079e224b96f4943eabe9792ad57 Mon Sep 17 00:00:00 2001 From: yew1eb Date: Fri, 3 Apr 2026 11:25:26 +0800 Subject: [PATCH 1/2] perf: SIMD short-circuit in JoinHashMap probe [AURON-2160] Optimize join hash map probe by checking hash_matched first before computing empty mask. This reduces ~50% SIMD instructions when hash hit rate is high (typical join scenarios). Before: Always compute both hash_matched and empty SIMD masks. After: Only compute empty mask when hash_matched has no hits. --- .../src/joins/join_hash_map.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/native-engine/datafusion-ext-plans/src/joins/join_hash_map.rs b/native-engine/datafusion-ext-plans/src/joins/join_hash_map.rs index 686dd9f0b..ffe756ffa 100644 --- a/native-engine/datafusion-ext-plans/src/joins/join_hash_map.rs +++ b/native-engine/datafusion-ext-plans/src/joins/join_hash_map.rs @@ -253,15 +253,26 @@ impl Table { let mut e = entries![i] as usize; loop { let hash_matched = self.map[e].hashes.simd_eq(Simd::splat(hashes[i])); - let empty = self.map[e].hashes.simd_eq(Simd::splat(0)); - if let Some(pos) = (hash_matched | empty).first_set() { + // Fast path: check hash match first (common case) + if let Some(pos) = hash_matched.first_set() { hashes[i] = unsafe { // safety: transmute MapValue(u32) to u32 std::mem::transmute(self.map[e].values[pos]) }; break; } + + // Slow path: check empty slot only when no match + let empty = self.map[e].hashes.simd_eq(Simd::splat(0)); + if empty.any() { + hashes[i] = unsafe { + // safety: transmute MapValue(u32) to u32 + std::mem::transmute(MapValue::EMPTY) + }; + break; + } + e += 1; e %= 1 << self.map_mod_bits; } From 7270b7002da74e48d3efd8970a8eda3ee29a0ec0 Mon Sep 17 00:00:00 2001 From: yew1eb Date: Tue, 7 Apr 2026 14:11:27 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../datafusion-ext-plans/src/joins/join_hash_map.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/native-engine/datafusion-ext-plans/src/joins/join_hash_map.rs b/native-engine/datafusion-ext-plans/src/joins/join_hash_map.rs index ffe756ffa..fbef6febc 100644 --- a/native-engine/datafusion-ext-plans/src/joins/join_hash_map.rs +++ b/native-engine/datafusion-ext-plans/src/joins/join_hash_map.rs @@ -266,10 +266,7 @@ impl Table { // Slow path: check empty slot only when no match let empty = self.map[e].hashes.simd_eq(Simd::splat(0)); if empty.any() { - hashes[i] = unsafe { - // safety: transmute MapValue(u32) to u32 - std::mem::transmute(MapValue::EMPTY) - }; + hashes[i] = MapValue::EMPTY.0; break; }