Increase 64-bit rotation from 20 to 26 bits on finalizer#56
Merged
Noratrieb merged 1 commit intorust-lang:masterfrom Feb 5, 2025
Merged
Conversation
Noratrieb
approved these changes
Feb 5, 2025
Member
Noratrieb
left a comment
There was a problem hiding this comment.
thanks! I'll merge and release this later today (if I forget please ping me again)
|
@Noratrieb While |
Member
|
The primary intended purpose of this crate is hashmap hashing, where stability doesn't really matter. I don't think this crate should be used for anything else, it's a very bad quality hash. That could probably be better noted in the readme. |
bgw
added a commit
to vercel/next.js
that referenced
this pull request
Apr 30, 2025
This includes rust-lang/rustc-hash#56 Apparently 2.1.0 has a bug that can cause lots of hashtable collisions for very large maps with more than `2^20` elements. We have some very large maps, so this seems potentially concerning.
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.
The current finalizer consisting of a right-rotation of 20 bits can create fairly catastrophic results if the bottom input bits are low-entropy and the hash table grows beyond 2^20 elements, see rust-lang/rust#135477 (comment).
In this PR I bumped the number of bits to 26 from 20 in order to allow for bigger hash tables. This is a palliative solution because it increases the chance of collisions from what I can gather. The proper solution that would render the whole rotention irrelevant would be to fix the hashbrown implementation in a way I could not describe here but @orlp and @Noratrieb definitely could if you ask them haha.
Further, I changed the tests in an ad-hoc manner because I couldn't do it otherwise, so if it makes sense to do it in another way please let me know.
Also, I changed the version number to 2.1.1 because the only change was a private constant that should not implicate anything anywhere, but of course if 2.2.0 makes more sense I'll change it right away.
If any other change is required, please let me know!