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

Don't hash the key when searching in an empty table. #305

Merged
merged 1 commit into from
Jan 6, 2022

Conversation

nnethercote
Copy link
Contributor

In rustc, approximately one third of all non-modifying lookups are on an
empty table!

In rustc, approximately one third of all non-modifying lookups are on an
empty table!
@nnethercote
Copy link
Contributor Author

Other workloads won't have this many lookups on empty tables, but it's simple and cheap enough to be worth considering. rust-lang/rust#92239 has details on the improvements seen in rustc.

@Amanieu
Copy link
Member

Amanieu commented Jan 6, 2022

Nice!

@bors r+

@bors
Copy link
Contributor

bors commented Jan 6, 2022

📌 Commit dec8e8c has been approved by Amanieu

@bors
Copy link
Contributor

bors commented Jan 6, 2022

⌛ Testing commit dec8e8c with merge 61d70a1...

@bors
Copy link
Contributor

bors commented Jan 6, 2022

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 61d70a1 to master...

Comment on lines +1099 to +1104
if self.table.is_empty() {
None
} else {
let hash = make_hash::<K, Q, S>(&self.hash_builder, k);
self.table.get(hash, equivalent_key(k))
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may make sense, if the map contains a single element and the table is small, to skip hashing and compare directly the key with the key of the single entry in the table

vtjnash pushed a commit to JuliaLang/julia that referenced this pull request Feb 25, 2022
Avoids hashing the input key for empty dictionaries.

Inspired by rust-lang/hashbrown#305.
staticfloat pushed a commit to JuliaCI/julia-buildkite-testing that referenced this pull request Mar 2, 2022
…ng#44341)

Avoids hashing the input key for empty dictionaries.

Inspired by rust-lang/hashbrown#305.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
…ng#44341)

Avoids hashing the input key for empty dictionaries.

Inspired by rust-lang/hashbrown#305.
hargoniX added a commit to hargoniX/lean4 that referenced this pull request Aug 28, 2023
kim-em pushed a commit to hargoniX/lean4 that referenced this pull request Aug 29, 2023
kim-em pushed a commit to hargoniX/lean4 that referenced this pull request Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants