1. 28
  1. 8

    (Are you wondering where the constant 0x517cc1b727220a95 comes from? 0xffff_ffff_ffff_ffff / 0x517c_c1b7_2722_0a95 = π.)

    Why is this magic number a good choice? Is it something to do with pi not having patterns in its digits? But then why use 1/pi vs pi, or some other irrational?

    1. 3

      The firefox hash looks similar to the old and well-known FNV hash (XOR then multiply), which I’m surprised the author didn’t mention at all.

      • Remove the rotate_left: tiny improvements on quite a few benchmarks, but moderate regressions on a smaller number, and not worthwhile.

      Since the rotate is an addition to FNV, I think the real takeaway is that it was not worth adding.

      1. 2

        Except FNV operates on bytes, whereas FxHash operates on 4-byte chunks.

        (Also, xor-then-multiply is FNV-1a. The original FNV is multiply-then-xor, which has the bad effect that the last byte hashed only affects the lower 8 bits of the hash, which are often lost when the hash is right-shifted into a table index. This burned me a few years ago.)

      2. 3

        Very nice investigation of a couple hash algorithms that are good for different purposes, and why they are good for different purposes.