[Bug libstdc++/95079] unorderd_map::insert_or_assign and try_emplace should only hash and mod once unless there is a rehash.

redbeard0531 at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Mar 2 13:40:52 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95079

--- Comment #5 from Mathias Stearn <redbeard0531 at gmail dot com> ---
@François Dumont: Sorry I didn't see your question earlier. The reason that
unordered_map perf hurts on 64-bit platforms is because it is designed to do a
size_t modulus-by-prime on every lookup, and on most platforms that is *very*
expensive (up to 100 cycles for 64 bits vs 20ish for 32 bits). Some very modern
CPUs have made improvements here, but it is still much more expensive than just
using power-of-2 buckets and masking, even if you need to hash the hash if you
don't trust the low order bits to have enough entropy. Unfortunately, fixing
this is a pretty big ABI break, so it isn't going to change any time soon.


More information about the Gcc-bugs mailing list