3 ms·
One "cheap" performance boost you could probably get is replacing your HashMaps with FxHashMap, https://docs.rs/fxhash/latest/fxhash/ https://docs.rs/fxhash/lat
by Twirrim 3y ago
One "cheap" performance boost you could probably get is replacing your HashMaps with FxHashMap, https://docs.rs/fxhash/latest/fxhash/ https://docs.rs/fxhash/latest/fxhash/, which uses a much cheaper/faster, but also not cryptographically secure, hashing algorithm. For these purposes, I doubt the hashing algorithm weakness would be an issue.
- Traubenfuchs 3y agoWhy the hell would a HashMap use a cryptographically secure hash?
- kaba0 3y agoI believe rust’s hashmap does have an implementation that is immune to timing-based attacks and that does have a performance cost. Maybe that’s what parent mixed it up with.
- Twirrim 3y agoI was trying to use the specific phrasing the fxhash crate authors used, but screwed it up. Brain was half asleep when I wrote my comment, I think. > It is not a cryptographically secure hash, so it is strongly recommended that you do not use this hash for cryptographic purproses. Furthermore, this hashing algorithm was not designed to prevent any attacks for determining collisions which could be used to potentially cause quadratic behavior in HashMaps. So it is not recommended to expose this hash in places where collissions or DDOS attacks may be a concern.
- kzrdude 3y agoHashMap uses SipHash. To call it cryptographically secure is not a clear way of summarizing what it provides. See Wikipedia for more info. Blurb: > It was designed to be efficient even for short inputs, with performance comparable to non-cryptographic hash functions, such as CityHash, this can be used to prevent denial-of-service attacks against hash tables ("hash flooding") [...]
- Traubenfuchs 3y ago> "hash flooding" I did not know this was a thing. What a massive amount of engineering effort is being wasted on protecting against outlandish attacks!
- rodrigodd 3y agoI am already using a non-cryptographic hasher. In fact, I am not doing any hashing at all, I am just assuming that the input is already random enough, and use a Hasher that just copies the input to output. But I still didn't measure the performance of that, so that may be something silly to do.
- Twirrim 3y agoSorry, in the blog post you were talking about the HashMap being expensive, and I didn't spot one of the usual "cheap" hashing libraries being in use. That's where I got wondering if you'd missed an easy boost.