perf: better derived Hashable for single field structures#11984
perf: better derived Hashable for single field structures#11984
Conversation
|
!bench |
|
Benchmark results for d2b44d6 against b81608d are in! @hargoniX Warnings (2)These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.
Large changes (1✅)
Small changes (280✅, 3🟥)Too many entries to display here. View the full report on radar instead. |
|
With these, rather than just special casing single field structures you can just make the first case structure MyProd where
a : Nat
b : Nat
deriving Hashable
#print instHashableMyProd.hash
-- | { a := a, b := a_1 } => mixHash (mixHash 0 (hash a)) (hash a_1)
#print instHashableProd
-- mixHash (hash a) (hash b)edit: Actually with inductives this doesn't work so well because if the hash for the first case is equivalent to You can do similarly with inductives, currently you get: inductive MySum where
| a : Nat -> MySum
| b : Nat -> MySum
deriving Hashable
#print instHashableMySum.hash
-- match x with
-- | MySum.a a => mixHash 0 (hash a)
-- | MySum.b a => mixHash 1 (hash a)but this could be (although this is arguably less useful given it only saves work in the first case) match x with
| MySum.a a => hash a
| MySum.b a => mixHash 0 (hash a) |
This PR changes the deriving handler for
Hashableto simply callhash xinstead ofmixHash 0 (hash x)for single field structures.Closes: #11818