Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[rust-compiler] Use rustc-hash FxHasher for all maps and sets#36811

Open
Boshen wants to merge 1 commit into
react:mainfrom
Boshen:rust-compiler/use-rustc-hash
Open

[rust-compiler] Use rustc-hash FxHasher for all maps and sets#36811
Boshen wants to merge 1 commit into
react:mainfrom
Boshen:rust-compiler/use-rustc-hash

Conversation

@Boshen

@Boshen Boshen commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Swaps the default hashers across the Rust compiler crates for rustc-hash's faster FxHasher.

Why

FxHasher is a simple, fast, non-cryptographic hasher. std's default (SipHash) is DoS-resistant but heavy — the compiler keys maps/sets almost entirely on small integer IDs (IdentifierId, BlockId, ScopeId, …) where that protection buys nothing. Switching gives:

  • Performance — faster hashing on the hot ID-keyed maps/sets used throughout the passes.
  • Slight binary size reduction — drops the heavy SipHash hasher pulled in by std's HashMap/HashSet.

Changes

  • std::collections::HashMap/HashSetrustc_hash::FxHashMap/FxHashSet
  • indexmap IndexMap/IndexSet now use FxBuildHasher, inlined as IndexMap<K, V, FxBuildHasher> (no FxIndexMap type aliases)
  • rustc-hash = "2" added to all 12 crate manifests
  • rustc_hash/indexmap imports consolidated into single brace imports at the top of each file

The change is serde-neutral: FxHashMap and IndexMap<_, _, FxBuildHasher> serialize to byte-identical JSON, and IndexMap keeps insertion order.

cargo check, cargo fmt --check, and cargo test all pass with no warnings.

Replace std HashMap/HashSet with rustc_hash FxHashMap/FxHashSet and switch
indexmap to the FxBuildHasher hasher across all compiler crates. Adds
rustc-hash = "2" to every crate and consolidates the imports to single
brace imports at the top of each file.
@meta-cla meta-cla Bot added the CLA Signed label Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant