Add hashmaps/microbenchmarks/insertHeavy benchmark#338
Merged
Conversation
aspiwack
approved these changes
Jul 23, 2021
Member
aspiwack
left a comment
There was a problem hiding this comment.
The influence of the salt is rather unexpected indeed.
For reference, hashWithSalt salt i (for i an integer) is implemented as (salt * 16777619) xor i.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a benchmark for
Data.HashMap.Mutable.Linearwhich inserts a bunch of keys in random order. Here're some details of the benchmark:Int's for which thehashvalue is salted with a large number.Here's the result of the benchmark on GHC HEAD (
378c0bba7d):One thing I found when I'm implementing this is that, when you remove the salt from the
hashfunction (and therefore making itidentityfor ourIntkeys) we are a lot faster. The fact that it gets faster makes sense, since there are no hash collisions (the largestIntis smaller than our capacity in this benchmark). But the fact that it gets almost twice as fast is curious, since I don't expect that much collisions. I had a look at our probe sequence lengths and found that most of the keys indeed did not have collisions; which means that even a few collisions slows downs our implementation disproportionately.Also, this has two minor improvements to the existing benchmark suite (see the individual commits). Another note about the implementation is that it looks a bit different than the existing HashMap benchmarks. It has two reasons: