From df38fefb092ac2258b53bad3eee268ba61fa863d Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 23 Jul 2026 03:39:40 +0000 Subject: [PATCH 1/2] Remove dead code from bun_hash - XxHash3 wrapper: HashObject.rs calls bun_highway::xxhash3_64 directly since #31491, leaving the bun_hash::XxHash3 wrapper unreferenced. - Murmur hash_uint* helpers: the 12 hash_uint32/64(_with_seed) fns on Murmur2_32/Murmur2_64/Murmur3_32 have never been called outside their own self-referential tests (which only asserted they match hash()). Verified with rg across src/, build/debug/codegen/, src/codegen/, packages/, test/ and *.classes.ts. bun bd builds, cargo test -p bun_hash passes, rust:check-all passes on all targets, hash.test.js passes. --- src/hash/lib.rs | 4 +- src/hash/murmur.rs | 171 --------------------------------------------- src/hash/xxhash.rs | 9 --- 3 files changed, 2 insertions(+), 182 deletions(-) diff --git a/src/hash/lib.rs b/src/hash/lib.rs index fc556e5801f5..2e5389f7f91a 100644 --- a/src/hash/lib.rs +++ b/src/hash/lib.rs @@ -12,7 +12,7 @@ //! | `cityHash64` | [`CityHash64::hash_with_seed`] | u64 → u64 | //! | `xxHash32` | [`XxHash32::hash`] | u32 → u32 | //! | `xxHash64` | [`XxHash64::hash`] | u64 → u64 | -//! | `xxHash3` | [`XxHash3::hash`] | u64 → u64 | +//! | `xxHash3` | `bun_highway::xxhash3_64` | u64 → u64 | //! | `murmur32v2` | [`Murmur2_32::hash_with_seed`] | u32 → u32 | //! | `murmur32v3` | [`Murmur3_32::hash_with_seed`] | u32 → u32 | //! | `murmur64v2` | [`Murmur2_64::hash_with_seed`] | u64 → u64 | @@ -31,7 +31,7 @@ pub use adler32::Adler32; pub use cityhash::{CityHash32, CityHash64}; pub use murmur::{Murmur2_32, Murmur2_64, Murmur3_32}; pub use rapidhash::RapidHash; -pub use xxhash::{XxHash3, XxHash32, XxHash64, XxHash64Streaming}; +pub use xxhash::{XxHash32, XxHash64, XxHash64Streaming}; #[cfg(test)] pub(crate) mod verify { diff --git a/src/hash/murmur.rs b/src/hash/murmur.rs index af4c377f0332..56ea36d30035 100644 --- a/src/hash/murmur.rs +++ b/src/hash/murmur.rs @@ -66,51 +66,6 @@ impl Murmur2_32 { h1 ^= h1 >> 15; h1 } - - #[inline] - pub fn hash_uint32(v: u32) -> u32 { - Self::hash_uint32_with_seed(v, DEFAULT_SEED) - } - - pub fn hash_uint32_with_seed(v: u32, seed: u32) -> u32 { - const M: u32 = 0x5bd1e995; - let len: u32 = 4; - let mut h1: u32 = seed ^ len; - let mut k1 = v.wrapping_mul(M); - k1 ^= k1 >> 24; - k1 = k1.wrapping_mul(M); - h1 = h1.wrapping_mul(M); - h1 ^= k1; - h1 ^= h1 >> 13; - h1 = h1.wrapping_mul(M); - h1 ^= h1 >> 15; - h1 - } - - #[inline] - pub fn hash_uint64(v: u64) -> u32 { - Self::hash_uint64_with_seed(v, DEFAULT_SEED) - } - - pub fn hash_uint64_with_seed(v: u64, seed: u32) -> u32 { - const M: u32 = 0x5bd1e995; - let len: u32 = 8; - let mut h1: u32 = seed ^ len; - let mut k1 = (v as u32).wrapping_mul(M); - k1 ^= k1 >> 24; - k1 = k1.wrapping_mul(M); - h1 = h1.wrapping_mul(M); - h1 ^= k1; - k1 = ((v >> 32) as u32).wrapping_mul(M); - k1 ^= k1 >> 24; - k1 = k1.wrapping_mul(M); - h1 = h1.wrapping_mul(M); - h1 ^= k1; - h1 ^= h1 >> 13; - h1 = h1.wrapping_mul(M); - h1 ^= h1 >> 15; - h1 - } } // ────────────────────────────────────────────────────────────────────────── @@ -156,44 +111,6 @@ impl Murmur2_64 { h1 ^= h1 >> 47; h1 } - - #[inline] - pub fn hash_uint32(v: u32) -> u64 { - Self::hash_uint32_with_seed(v, DEFAULT_SEED as u64) - } - - pub fn hash_uint32_with_seed(v: u32, seed: u64) -> u64 { - const M: u64 = 0xc6a4a7935bd1e995; - let len: u64 = 4; - let mut h1: u64 = seed ^ len.wrapping_mul(M); - let k1: u64 = v as u64; - h1 ^= k1; - h1 = h1.wrapping_mul(M); - h1 ^= h1 >> 47; - h1 = h1.wrapping_mul(M); - h1 ^= h1 >> 47; - h1 - } - - #[inline] - pub fn hash_uint64(v: u64) -> u64 { - Self::hash_uint64_with_seed(v, DEFAULT_SEED as u64) - } - - pub fn hash_uint64_with_seed(v: u64, seed: u64) -> u64 { - const M: u64 = 0xc6a4a7935bd1e995; - let len: u64 = 8; - let mut h1: u64 = seed ^ len.wrapping_mul(M); - let mut k1 = v.wrapping_mul(M); - k1 ^= k1 >> 47; - k1 = k1.wrapping_mul(M); - h1 ^= k1; - h1 = h1.wrapping_mul(M); - h1 ^= h1 >> 47; - h1 = h1.wrapping_mul(M); - h1 ^= h1 >> 47; - h1 - } } // ────────────────────────────────────────────────────────────────────────── @@ -264,52 +181,6 @@ impl Murmur3_32 { h1 ^= len; fmix32(h1) } - - #[inline] - pub fn hash_uint32(v: u32) -> u32 { - Self::hash_uint32_with_seed(v, DEFAULT_SEED) - } - - pub fn hash_uint32_with_seed(v: u32, seed: u32) -> u32 { - const C1: u32 = 0xcc9e2d51; - const C2: u32 = 0x1b873593; - let len: u32 = 4; - let mut h1: u32 = seed; - let mut k1 = v.wrapping_mul(C1); - k1 = Self::rotl32(k1, 15); - k1 = k1.wrapping_mul(C2); - h1 ^= k1; - h1 = Self::rotl32(h1, 13); - h1 = h1.wrapping_mul(5).wrapping_add(0xe6546b64); - h1 ^= len; - fmix32(h1) - } - - #[inline] - pub fn hash_uint64(v: u64) -> u32 { - Self::hash_uint64_with_seed(v, DEFAULT_SEED) - } - - pub fn hash_uint64_with_seed(v: u64, seed: u32) -> u32 { - const C1: u32 = 0xcc9e2d51; - const C2: u32 = 0x1b873593; - let len: u32 = 8; - let mut h1: u32 = seed; - let mut k1 = (v as u32).wrapping_mul(C1); - k1 = Self::rotl32(k1, 15); - k1 = k1.wrapping_mul(C2); - h1 ^= k1; - h1 = Self::rotl32(h1, 13); - h1 = h1.wrapping_mul(5).wrapping_add(0xe6546b64); - k1 = ((v >> 32) as u32).wrapping_mul(C1); - k1 = Self::rotl32(k1, 15); - k1 = k1.wrapping_mul(C2); - h1 ^= k1; - h1 = Self::rotl32(h1, 13); - h1 = h1.wrapping_mul(5).wrapping_add(0xe6546b64); - h1 ^= len; - fmix32(h1) - } } #[cfg(test)] @@ -317,58 +188,16 @@ mod tests { use super::*; use crate::verify::{smhasher_32, smhasher_64}; - #[test] - fn murmur2_32_uint() { - let v0: u32 = 0x12345678; - let v1: u64 = 0x1234567812345678; - assert_eq!( - Murmur2_32::hash(&v0.to_le_bytes()), - Murmur2_32::hash_uint32(v0) - ); - assert_eq!( - Murmur2_32::hash(&v1.to_le_bytes()), - Murmur2_32::hash_uint64(v1) - ); - } - #[test] fn murmur2_32_smhasher() { assert_eq!(smhasher_32(Murmur2_32::hash_with_seed), 0x27864C1E); } - #[test] - fn murmur2_64_uint() { - let v0: u32 = 0x12345678; - let v1: u64 = 0x1234567812345678; - assert_eq!( - Murmur2_64::hash(&v0.to_le_bytes()), - Murmur2_64::hash_uint32(v0) - ); - assert_eq!( - Murmur2_64::hash(&v1.to_le_bytes()), - Murmur2_64::hash_uint64(v1) - ); - } - #[test] fn murmur2_64_smhasher() { assert_eq!(smhasher_64(Murmur2_64::hash_with_seed), 0x1F0D3804); } - #[test] - fn murmur3_32_uint() { - let v0: u32 = 0x12345678; - let v1: u64 = 0x1234567812345678; - assert_eq!( - Murmur3_32::hash(&v0.to_le_bytes()), - Murmur3_32::hash_uint32(v0) - ); - assert_eq!( - Murmur3_32::hash(&v1.to_le_bytes()), - Murmur3_32::hash_uint64(v1) - ); - } - #[test] fn murmur3_32_smhasher() { assert_eq!(smhasher_32(Murmur3_32::hash_with_seed), 0xB0F57EE3); diff --git a/src/hash/xxhash.rs b/src/hash/xxhash.rs index a1d387e65164..3adc8c94e69b 100644 --- a/src/hash/xxhash.rs +++ b/src/hash/xxhash.rs @@ -59,12 +59,3 @@ impl Default for XxHash64Streaming { Self::new(0) } } - -pub struct XxHash3; - -impl XxHash3 { - #[inline] - pub fn hash(seed: u64, input: &[u8]) -> u64 { - bun_highway::xxhash3_64(seed, input) - } -} From 740cc8b36f80d15d8900d6ee9de36f1464b14d25 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 23 Jul 2026 03:47:07 +0000 Subject: [PATCH 2/2] Drop stale XxHash3 mention from xxhash.rs module doc --- src/hash/xxhash.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hash/xxhash.rs b/src/hash/xxhash.rs index 3adc8c94e69b..19b24740dd05 100644 --- a/src/hash/xxhash.rs +++ b/src/hash/xxhash.rs @@ -1,9 +1,9 @@ -//! XxHash32 / XxHash64 / XxHash3. +//! XxHash32 / XxHash64. //! //! Thin wrappers over the C++/Highway xxHash kernel in -//! `src/jsc/bindings/xxhash3.cpp` (exposed by `bun_highway`). XXH3's long-input -//! stripe loop is runtime-dispatched to the widest SIMD ISA the CPU supports; -//! XXH32/XXH64 are scalar (no SIMD form exists in the reference). Output is +//! `src/jsc/bindings/xxhash3.cpp` (exposed by `bun_highway`). +//! XXH32/XXH64 are scalar (no SIMD form exists in the reference); +//! `HashObject.rs` calls `bun_highway::xxhash3_64` directly for XXH3. Output is //! bit-identical to the xxHash //! reference test vectors — verified against the reference (and across every //! dispatch target) by `test/js/bun/util/hash.test.js`, which runs in CI.