[rust-compiler] Use rustc-hash FxHasher for all maps and sets#36811
Open
Boshen wants to merge 1 commit into
Open
[rust-compiler] Use rustc-hash FxHasher for all maps and sets#36811Boshen wants to merge 1 commit into
Boshen wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Swaps the default hashers across the Rust compiler crates for rustc-hash's faster
FxHasher.Why
FxHasheris 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:HashMap/HashSet.Changes
std::collections::HashMap/HashSet→rustc_hash::FxHashMap/FxHashSetindexmapIndexMap/IndexSetnow useFxBuildHasher, inlined asIndexMap<K, V, FxBuildHasher>(noFxIndexMaptype aliases)rustc-hash = "2"added to all 12 crate manifestsrustc_hash/indexmapimports consolidated into single brace imports at the top of each fileThe change is serde-neutral:
FxHashMapandIndexMap<_, _, FxBuildHasher>serialize to byte-identical JSON, andIndexMapkeeps insertion order.cargo check,cargo fmt --check, andcargo testall pass with no warnings.