rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.9k stars 914 forks source link

Using a custom hasher in hash maps #2856

Open notgull opened 1 year ago

notgull commented 1 year ago

At the moment, the Wayland backend uses fnv for its hash maps, while all of the other backends (to my knowledge) just use the std SipHash algorithm. According to @kchibisov in Matrix, this was done because it improved benchmark times in Alacritty. If so, it would be nice to port this optimization to the other backends.

There are other hashing algorithms as well, like ahash, rustc_hash and nohash. We should compare all of these, as well as plain std hash maps, and see which one best fits our use case.

daxpedda commented 1 year ago

fnv is unmaintained, in the meantime the Rust ecosystem has largely moved towards hashbrown, which uses ahash under the hood.

kchibisov commented 1 year ago

I wouldn't call it unmaintained, it's complete, no changes required for it.

Though, ahash is a better default.

kchibisov commented 1 year ago

I've compared the some of the hash functions in alacritty and ahash was much better when doing get than fnv, I've also included default std, but it was way slower... The benchmark I've used is available here https://git.sr.ht/~kchibisov/hash-bench.

https://github.com/alacritty/alacritty/pull/7106#issue-1816728904