-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Re-evaluate Hash{Set,Map}
vs FxHash{Set,Map}
once #69152 lands
#69153
Comments
You could fork the rustc-hash crate, make it use |
It may also make sense to evaluate ahash, the hash function that hashbrown switched to due to fxhash's poor hash quality. |
Didn't we also use a custom hasher to bypass randomness? |
Note to self: |
I measured this change locally, on top of the
Every single run of every single benchmark regressed, by 3.9% to 84.7%! I had a microbenchmark where Oh well, at least it confirms that |
@nnethercote Just to confirm, when you're talking about I had seen #69153 (comment) and got myself confused into thinking your results were for I'm not surprised |
I can confirm similar findings between DefaultHasher and fx in
my own codebases (although belatedly)
Hardware accelerated hashes sound nice until you consider the bigger than
usual performance cliff when acceleration is not available. Using something like aHash
is fine when you know you only care about x86. Rustc cares about way more.
…On Fri, 21 Feb 2020, 00:09 Eduard-Mihai Burtescu, ***@***.***> wrote:
@nnethercote <https://github.com/nnethercote> Just to confirm, when
you're talking about DefaultHasher, it's still SipHash, right?
I had seen #69153 (comment)
<#69153 (comment)>
and got myself confused into thinking your results were for aHash.
I'm not surprised SipHash is still a slowdown, given its intended usecase
(DoS protection), I don't think we can get away with a hash function "that
good" unless we can heavily rely on hardware acceleration (which,
ironically, might make actual cryptographic hashes faster; I guess the
hardware acceleration might be reusable for something weaker than
full-blown AES, but I have no idea).
—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
<#69153?email_source=notifications&email_token=AAFFZUWZRSYYE6NFQE6M4G3RD35THA5CNFSM4KU7TWWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMQRPKY#issuecomment-589371307>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFFZUXWBHY3N73T2WRESXTRD35THANCNFSM4KU7TWWA>
.
|
AHash actually has a fallback hash which is almost as fast as FxHash but avoids the issues with poor distribution. This is the main reason why I chose it as the default hash function for hashbrown. |
It's |
I just tried Fallback
|
I brought that up earlier, and it's worse than that because it breaks deterministic builds. But you can turn it off (look at the feature list in However, being slightly worse than |
I tried that but it caused compile errors because the you don't get a |
|
rustc uses
FxHash{Set,Map}
everywhere rather thanHash{Set,Map}
, because theDefaultHasher
used byHash{Set,Map}
is slow.But once #69152 lands,
DefaultHasher
will be a lot faster when hashing integers, which is a common case; in one microbenchmark I saw a ~2.5x speed-up. Combine that with the fact thatFxHasher
is a lower-quality hasher and so tends to result in more collisions, and the default hash tables might be faster. (On a different microbenchmark I saw thatHashSet<u32>
was a little bit faster thanFxHashSet<u32>
.)We should evaluate this, probably by replacing every
FxHash{Set,Map}
withHash{Set,Map}
. (It keeps things simpler if we exclusively used one or the other, rather than a mix.)I briefly tried to do this, but we have a lint that produces this message if you try to use
Hash{Set,Map}
: "error: Prefer FxHashSet over HashSet, it has better performance". I couldn't work out how to disable it.cc @rust-lang/wg-compiler-performance
cc @cbreeden
cc @Amanieu
The text was updated successfully, but these errors were encountered: