-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ahash for IndexMap and IndexSet hasher #12935
Merged
Merged
Conversation
This file contains 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
The ahash hasher offers better performace as a drop in replacement for the stdlib hash algorithm. This is a large reason we use the hashbrown crate for our HashMap type in Qiskit (along with rayon support). The indexmap crate doesn't use ahash by default however, so we typically switch to it anywhere we use IndexMap or IndexSet to match the lookup performance of hashbrown in places where we need to preserve insertion order. However, there were a couple of spots where we missed this in the rust code, this commit corrects these oversights.
mtreinish
added
Changelog: None
Do not include in changelog
Rust
This PR or issue is related to Rust code in the repository
labels
Aug 9, 2024
mtreinish
requested review from
alexanderivrii,
ShellyGarion and
a team
as code owners
August 9, 2024 20:59
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 10325632714Details
💛 - Coveralls |
jakelishman
approved these changes
Aug 9, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The super intermediate use in qasm3
feels like it's probably not too worth bothering with, but it's not bad to be uniform.
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Aug 13, 2024
In the `target_transpiler/mod.rs` module we were using ahash::HashSet for a hash set implementation, but the rest of Qiskit has standardized on using hashbrown for the `HashSet` and `HashMap` types. Hashbrown uses ahash for it's hashing algorithm but it also provides other advantages. To ensure that hash sets are compatible across the library we should be using the same library for everything. To support this goal, this commit also adds a clippy rule that raises a warning if the std library hashmap or hashset is used, or the versions from ahash. This means with our current dependency set the only allowed hashset types are `hashbrown::HashMap`/`HashSet` and `indexmap::IndexMap`/`IndexSet` (for where we need to maintain insertion order). Ideally we'd have a rule that forces the use of ahash with `IndexMap` and `IndexSet` (see Qiskit#12935) but I don't think clippy exposes an option to enable something like that.
github-merge-queue bot
pushed a commit
that referenced
this pull request
Aug 13, 2024
In the `target_transpiler/mod.rs` module we were using ahash::HashSet for a hash set implementation, but the rest of Qiskit has standardized on using hashbrown for the `HashSet` and `HashMap` types. Hashbrown uses ahash for it's hashing algorithm but it also provides other advantages. To ensure that hash sets are compatible across the library we should be using the same library for everything. To support this goal, this commit also adds a clippy rule that raises a warning if the std library hashmap or hashset is used, or the versions from ahash. This means with our current dependency set the only allowed hashset types are `hashbrown::HashMap`/`HashSet` and `indexmap::IndexMap`/`IndexSet` (for where we need to maintain insertion order). Ideally we'd have a rule that forces the use of ahash with `IndexMap` and `IndexSet` (see #12935) but I don't think clippy exposes an option to enable something like that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Changelog: None
Do not include in changelog
Rust
This PR or issue is related to Rust code in the repository
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.
Summary
The ahash hasher offers better performace as a drop in replacement for the stdlib hash algorithm. This is a large reason we use the hashbrown crate for our HashMap type in Qiskit (along with rayon support). The indexmap crate doesn't use ahash by default however, so we typically switch to it anywhere we use IndexMap or IndexSet to match the lookup performance of hashbrown in places where we need to preserve insertion order. However, there were a couple of spots where we missed this in the rust code, this commit corrects these oversights.
Details and comments