|
3 | 3 | [](https://crates.io/crates/rustc-hash) |
4 | 4 | [](https://docs.rs/rustc-hash) |
5 | 5 |
|
6 | | -A speedy, non-cryptographic hashing algorithm used by `rustc` and Firefox. |
| 6 | +A speedy, non-cryptographic hashing algorithm used by `rustc`. |
7 | 7 | The [hash map in `std`](https://doc.rust-lang.org/std/collections/struct.HashMap.html) uses SipHash by default, which provides resistance against DOS attacks. |
8 | | -These attacks aren't as much of a concern in the compiler so we prefer to use the quicker, non-cryptographic Fx algorithm. |
9 | | - |
10 | | -The Fx algorithm is a unique one used by Firefox. It is fast because it can hash eight bytes at a time. |
11 | | -Within `rustc`, it consistently outperforms every other tested algorithm (such as FNV). |
12 | | -The collision rate is similar or slightly worse than other low-quality hash functions. |
| 8 | +These attacks aren't as much of a concern in the compiler so we prefer to use a |
| 9 | +quicker, non-cryptographic hash algorithm. |
| 10 | + |
| 11 | +The original hash algorithm provided by this crate was one taken from Firefox, |
| 12 | +hence the hasher it provides is called FxHasher. This name is kept for backwards |
| 13 | +compatibility, but the underlying hash has since been replaced. The current |
| 14 | +design for the hasher is a polynomial hash finished with a single bit rotation, |
| 15 | +together with a wyhash-inspired compression function for strings/slices, both |
| 16 | +designed by Orson Peters. |
| 17 | + |
| 18 | +Within `rustc`, it consistently outperforms every other tested algorithm or |
| 19 | +variation, despite its simplicity. Spending more CPU cycles on a higher quality |
| 20 | +hash does not reduce hash collisions enough to be worth the cost on real-world |
| 21 | +benchmarks. |
13 | 22 |
|
14 | 23 | ## Usage |
15 | 24 |
|
|
0 commit comments