Skip to content
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 1 commit into from
Aug 9, 2024

Conversation

mtreinish
Copy link
Member

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

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 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
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @kevinhartman
  • @mtreinish

@coveralls
Copy link

Pull Request Test Coverage Report for Build 10325632714

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 2 files are covered.
  • 21 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.01%) to 89.725%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 2 91.48%
crates/qasm2/src/parse.rs 18 96.69%
Totals Coverage Status
Change from base Build 10324625836: -0.01%
Covered Lines: 67363
Relevant Lines: 75077

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a 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.

@jakelishman jakelishman enabled auto-merge August 9, 2024 21:35
@jakelishman jakelishman added this pull request to the merge queue Aug 9, 2024
Merged via the queue into Qiskit:main with commit 6aa933c Aug 9, 2024
15 checks passed
@mtreinish mtreinish deleted the ahash-the-index branch August 9, 2024 23:16
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants