-
Notifications
You must be signed in to change notification settings - Fork 293
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
Conversation
In rustc, approximately one third of all non-modifying lookups are on an empty table!
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. |
Nice! @bors r+ |
📌 Commit dec8e8c has been approved by |
☀️ Test successful - checks-actions |
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)) | ||
} |
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.
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
Avoids hashing the input key for empty dictionaries. Inspired by rust-lang/hashbrown#305.
…ng#44341) Avoids hashing the input key for empty dictionaries. Inspired by rust-lang/hashbrown#305.
…ng#44341) Avoids hashing the input key for empty dictionaries. Inspired by rust-lang/hashbrown#305.
In rustc, approximately one third of all non-modifying lookups are on an
empty table!