Skip to content

Commit 3e39d8e

Browse files
authored
Merge pull request #37 from orlp/faster-hash
Replace hash with faster and better finalized hash
2 parents 1c85035 + 0a95d9d commit 3e39d8e

File tree

3 files changed

+270
-105
lines changed

3 files changed

+270
-105
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rustc-hash"
33
version = "1.2.0"
44
authors = ["The Rust Project Developers"]
5-
description = "A speedy, non-cryptographic hashing algorithm used by rustc and Firefox"
5+
description = "A speedy, non-cryptographic hashing algorithm used by rustc"
66
license = "Apache-2.0/MIT"
77
readme = "README.md"
88
keywords = ["hash", "hasher", "fxhash", "rustc"]
@@ -12,6 +12,7 @@ edition = "2021"
1212
[features]
1313
default = ["std"]
1414
std = []
15+
nightly = []
1516
rand = ["dep:rand", "std"]
1617

1718
[dependencies]

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
[![crates.io](https://img.shields.io/crates/v/rustc-hash.svg)](https://crates.io/crates/rustc-hash)
44
[![Documentation](https://docs.rs/rustc-hash/badge.svg)](https://docs.rs/rustc-hash)
55

6-
A speedy, non-cryptographic hashing algorithm used by `rustc` and Firefox.
6+
A speedy, non-cryptographic hashing algorithm used by `rustc`.
77
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 a concern in the compiler so we prefer to use a quicker,
9+
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+
For `rustc` we have tried many different hashing algorithms. Hashing speed is
19+
critical, especially for single integers. Spending more CPU cycles on a higher
20+
quality hash does not reduce hash collisions enough to make the compiler faster
21+
on real-world benchmarks.
1322

1423
## Usage
1524

0 commit comments

Comments
 (0)