rust-lang / rust-lang/rust-clippy
Suggest alternative hashers for HashMap
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Time for another crazy lint suggestion by yours truly! 😄
After seeing this hash performance benchmark and being overwhelmed by too many graphs with colored lines, I came to one conclusion: Key size and security are probably the only things that influence your choice of hasher.
And I think that in some instances of HashMap<K,V> you can statically determine the number of bytes in K! It won't work for all those cases where you want a HashMap<String, T> (which I hope is not because you like stringly-typed programs!). But for cases where the key is a primitive (a number type), or a custom data type built out of primitives (less than 24 bytes), clippy can look at the number of bytes and say: Better use (FNV|City64) here if this is not based on user input!
I'd really try to break it down to something easy, e.g. FNV for ≤8 bytes, City64 otherwise.
(A 'conclusion' drawn by looking at the table at the end of that article and assuming that the performance characteristics will be the same in the Rust version; also, I know many Rust projects are already using FNV.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the HashMap<K,V> linting entry point and read the linked hash performance benchmark, focusing on the proposed FNV and City64 choices for primitive or small custom keys. The issue names no repository files or tests; done would require settling the key-size and user-input rules and defining how the lint should recommend an alternative hasher.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100