Skip to content

feat(hash): SipHash, rapidhash V3, differential test vs libxxhash, latency benchmark - #219

Merged
helly25 merged 7 commits into
mainfrom
hash/medium-batch
Jul 4, 2026
Merged

feat(hash): SipHash, rapidhash V3, differential test vs libxxhash, latency benchmark#219
helly25 merged 7 commits into
mainfrom
hash/medium-batch

Conversation

@helly25

@helly25 helly25 commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Medium tier of mbo/hash/TODO.md, in one batch.

SipHash — the security story (siphash::Algorithm)

Constexpr-safe SipHash-c-d: canonical SipHash-2-4 (GetHash64(data, k0, k1)) and SipHash-1-3 (GetHash64Sip13), reference 128-bit-key API. Verified against reference vectors (the empty-input value 0x726fdb47dd0e0e31 matches the SipHash paper's test-vector table). The Algorithm plug-in derives the key from the 64-bit seed as (seed, Fmix64(seed)) — documented: adversarial DoS protection requires a secret seed.

rapidhash V3 — the small-key latency champion (rapidhash::Algorithm)

Constexpr-safe transcription of the reference FAST variant (wyhash family, SMHasher3-clean, MIT). Vectors generated by compiling the official rapidhash.h across every dispatch branch (0/1–3/4–7/8–16/17–112 ladder/113/224/225/448/1024/3000 × seeds). hash_internal::Mult128 added (full 64×64→128, both halves).

Differential test vs the real xxHash library

hash_differential_test: our xxh64/xxh3 vs libxxhash 0.8.3 over 40k+ randomized (input, seed, length) cases plus 100 KB buffers — bit-for-bit agreement, including against the reference's SIMD path. Far stronger than fixed vectors. (Pulled as a test-only http_archive; the BCR module's BUILD predates Bazel 9's rule-autoload removal.)

Mixed-length latency benchmark

BmHash64Latency<Algo>/{16,64,1024}: keys of unpredictable random length, each hash result selecting the next key (serialized chain) — measuring what hash-table workloads actually pay. First results (Apple clang) flip the throughput ranking:

max_len mix rapidhash xxh3 mh siphash24
≤16 B 11.0 ns 12.2 16.6 20.7
≤64 B 12.8 ns 14.1 27.7 27.2
≤1 KB 28.4 ns 42.4 57.2 259

rapidhash's small-key-latency reputation confirmed; siphash pays the documented DoS-resistance premium.

Also

  • All eight algorithms now run the full typed framework (canonical vectors, avalanche, seed-avalanche, structured keys, collisions, constexpr parity).
  • TODO.md: medium tier cleared except the one-off SMHasher3 run; XXH3-128 queued as the file-checksum follow-up; MD5/SHA recorded as a non-goal (looks cryptographic / is broken; BoringSSL for legacy interop) per review discussion.

helly25 and others added 7 commits July 4, 2026 11:49
…tency benchmark

Medium tier of mbo/hash/TODO.md:

- SipHash (hash_siphash.h): constexpr-safe SipHash-c-d (canonical 2-4 via
  GetHash64, 1-3 via GetHash64Sip13) with the reference 128-bit key API;
  verified against reference vectors (empty-input value matches the SipHash
  paper's table). The keyed, hash-flooding-resistant option the library
  lacked; Algorithm derives the key from the seed as (seed, Fmix64(seed)),
  documented as requiring a secret seed for adversarial protection.

- rapidhash V3 (hash_rapidhash.h): constexpr-safe transcription of the
  reference FAST variant (wyhash family; small-key latency champion,
  SMHasher3-clean); verified against vectors generated by compiling the
  official header across every dispatch branch. hash_internal gains Mult128
  (full 64x64->128, both halves).

- Differential test (hash_differential_test.cc): our xxh64/xxh3 vs the actual
  reference library over 40k+ randomized (input, seed, length) cases incl.
  block boundaries and 100KB buffers - bit-for-bit agreement, proving the
  scalar transcription matches even the reference's SIMD path. Reference
  xxHash 0.8.3 pulled as a test-only http_archive (the BCR module's BUILD
  predates Bazel 9's rule-autoload removal).

- Mixed-length latency benchmark (BmHash64Latency): unpredictable key sizes
  with a serialized hash->index dependency chain. Instantly instructive: the
  ranking flips vs hot-loop throughput (rapidhash 11ns < xxh3 12.2 < mh 16.6
  at 0..16B mixes).

TODO.md: medium tier cleared except the one-off SMHasher3 run; XXH3-128 added
as a future item; MD5/SHA recorded as a non-goal (use BoringSSL; our fast
file-identity answer is XXH3).
…ion over crypto-lib dependency

BoringSSL is live-at-head, unversioned, and has a history of
non-reproducible archives - an unverifiable supply chain for exactly the
code that most needs verifying. Digests are spec-frozen pure functions;
if interop is ever needed, transcribe + pin against NIST vectors in-repo.
The 32-bit counterpart of Hash128To64: all 64 bits contribute. Plain
truncation would be sound for the strong algorithms (full-avalanche
finalizers), but the fold is the correct default for every algorithm -
FNV-1a's low bits are biased and XOR-folding is that algorithm's official
shrinking recommendation.
Adds the HasGetHash32 concept, Hasher<Algo>::GetHash32, and the top-level
GetHash32<Algo>(data, seed). Algorithms may provide a native 32-bit variant
(e.g. a future canonical XXH32 / FNV-1a-32 / murmur3-x86); everything else
synthesizes the XOR-fold of the 64-bit hash (Hash64To32) - the per-algorithm
correct approach, selected automatically.
…ty BUILD file

Fixes four design problems with the differential test's reference archive:

- The BUILD file is a real file (third_party/xxhash/xxhash.BUILD.bazel), not
  an inline build_file_content string. third_party/ holds per-dependency
  directories for external BUILD files and patches; the files are named
  <dep>.BUILD.bazel so they never load as helly25_mbo packages. (A nested
  MODULE.bazel boundary was tried first: Bazel 9 does not treat it as a
  package-traversal boundary - the BUILD file loaded as a main-repo package.)
- The library is testonly.
- Visibility is restricted to //mbo/hash.
- The http_archive moved to bazelmod/dev.MODULE.bazel with
  dev_dependency = True: consumers of helly25_mbo never fetch it. The
  differential test is tagged manual so consumer wildcards never analyze a
  target whose dependency does not exist for them; our CI runs it explicitly.
@helly25
helly25 disabled auto-merge July 4, 2026 14:22
@helly25
helly25 merged commit 8b39a56 into main Jul 4, 2026
24 checks passed
@helly25
helly25 deleted the hash/medium-batch branch July 4, 2026 14:23
helly25 added a commit that referenced this pull request Jul 4, 2026
# Conflicts:
#	CHANGELOG.md
#	mbo/hash/hash_differential_test.cc
#	mbo/hash/hash_test.cc
helly25 added a commit that referenced this pull request Jul 4, 2026
# Conflicts:
#	mbo/hash/TODO.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants