rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.66k stars 12.75k forks source link

compare compiler performance with `hashbrown` #55514

Closed nikomatsakis closed 5 years ago

nikomatsakis commented 6 years ago

This https://github.com/Amanieu/hashbrown crate looks nice!

We should do a performance comparison.

cc @Amanieu

Amanieu commented 5 years ago

This comes at the cost of only storing 7 bits of the hash (you still need one bit for empty/full). So in theory we could avoid rehashing up to a capacity of 128, but past that we need to rehash to retrieve the higher bits.

The 7 bits stored in the table are taken from the top bits of the hash code, while the bits used to determine the initial search position in the array are taken from the bottom bits. This is important since it means that when we find a matching control byte in the table, we have actually matched both the top and bottom bits of the hash code, which significantly decreases the chance of false positives.

However this means that these 7 bits are completely useless when rehashing, since they don't contain the bits used for determining the position in the array.

Gankra commented 5 years ago

Ah dang, well in my defense I haven't gotten to that part of the code review yet :)

michaelwoerister commented 5 years ago

Ah, interesting. Thanks for the info!

mominul commented 5 years ago

When will be the new HashMap implementation(hashbrown) stabilized?

lnicola commented 5 years ago

@mominul On July 4th, in 1.36, if I recall correctly.

Gankra commented 5 years ago

Closing: performance was explored, it was excellent, it is now the implementation of std::collections::HashMap (and Set).