Rust's default HashMap
hasher is SipHash, which is considerably slower in some cases (for integers, for example), but it provides a HashDoS protection. As described here, the NoHashHasher
can be like 50 times faster than the default hasher and 10-20 times faster than FNV and FX hashers (not always, of course, but in some cases like the one described there).
In my personal experience, I'd very rarely need the extra protection agains HashDoS attacks. For example, if I put database IDs as keys and those IDs were autoincrement-based, I really don't see much of a risk there. Nonetheless, I understand there is a good reason to have a safer hasher as the default (better safe than sorry).
So when we know we are not exposed to any risk for HashDoS attacks and need to use 64-bit or smaller integers as keys, are there any reasons to refrain from using NoHashHasher
? Obviously, performance will not always be better and it's clear in certain cases it might even perform worse than FNV/FX hashers. I am specifically asking about non-obvious risks, downsides or special rules to follow in situations like the one described in the linked question, where it's clear NoHashHasher
shows an excellent performance.