From b0439faf244c35d032d5e50656c30c7ca8d70987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Massot?= Date: Fri, 9 Oct 2026 12:06:46 +0200 Subject: [PATCH] perf(stacker): compare short keys without memcmp calls double_check_trick compared [u8] sub-slices, which can be lowered to a memcmp call (it was on aarch64: ~13% of SpecializedPostingsWriter::subscribe). Comparing fixed-size arrays compiles to loads and compares. Index Body only (OTel logs, positions): -5%. --- stacker/src/fastcmp.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stacker/src/fastcmp.rs b/stacker/src/fastcmp.rs index 490f67cd5..91c078b8a 100644 --- a/stacker/src/fastcmp.rs +++ b/stacker/src/fastcmp.rs @@ -69,7 +69,11 @@ fn short_compare(left: &[u8], right: &[u8]) -> bool { #[inline(always)] fn double_check_trick(left: &[u8], right: &[u8]) -> bool { - left[0..SIZE] == right[0..SIZE] && left[left.len() - SIZE..] == right[right.len() - SIZE..] + // Fixed-size array comparisons compile to plain loads and compares; comparing `[u8]` + // sub-slices can be lowered to a `memcmp` call (seen on aarch64). + let head = |slice: &[u8]| -> [u8; SIZE] { slice[..SIZE].try_into().unwrap() }; + let tail = |slice: &[u8]| -> [u8; SIZE] { slice[slice.len() - SIZE..].try_into().unwrap() }; + head(left) == head(right) && tail(left) == tail(right) } #[cfg(test)]