RFC: improving performance of `deriving Hashable` on single-field structures
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Proposal
The hash produced by deriving Hashable on a single-field structure should be the same as the hash of the field type.
Currently, these two types have very different hashes, where the structure hash has a large slowdown compared to the other one:
abbrev T := Nat
structure U where
value: Nat
deriving Hashable
On our benchmarks that rely a lot on hashmaps, going from U to T lead to a 2x slowdown overall, whereas the two types are representing exactly the same thing.
Manually deriving the Hashable removes that slowdown, and I believe this implementation should be the one generated by deriving Hashable
instance : Hashable U where
hash u := hash u.value
Impact
Add 👍 to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add 👍 to it.
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
No files, tests, or entry points are named. Start by locating the deriving Hashable implementation and relevant benchmarks, then determine how single-field structures are handled; done means the generated hash matches the field hash without regressing other derived instances.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100