Some Bits: Nelson's log

xxhash notes

Following up on a post 7 years ago, there now seems to be a consensus for a hash / checksum algorithm that’s not cryptographic. xxhash. Some variants are literally faster than memcpy, which is quite a trick. (I assume it’s the SIMD instructions).

xxhash has a bunch of implementations, I’m using the Ubuntu version. It comes in four flavors: 32, 64, 128 bit, and an alternative 64 bit (H3) that’s the fastest. Oddly the 128 version is the fastest of the first three, then the 64 bit.

This reimplementation blog post has some details on the algorithm. The speed comes from a parallel design meant for SIMD calculation. The actual checksumming boils down to rotate(state + (data * prime2)) * prime1. I’m a little surprised it’s a multiply and not a shift and xor or something but I know nothing about modern CPU speed.

I did a very simplistic benchmark: time dd if=/dev/zero bs=1024k count=1024 | xxhsum -H3 and took the best time of several runs.

  • no hash (send to /dev/null): 30ms
  • H0: 245ms
  • H1: 222ms
  • H2: 224ms
  • H3: 224ms
  • md5sum: 1250ms

Safe to say xxhash in any of its forms is so fast that I/O speeds and overhead dominate the CPU for the calculation. No wonder people embed this thing in filesystems, etc. It has very little cost.