More hash optimization#50041
Merged
oscardssmith merged 3 commits intoJuliaLang:masterfrom Jun 7, 2023
Merged
Conversation
…d hash of arbitrary real types by not hashing the denominatior when it is one
Contributor
|
Do you have benchmarks? |
Member
Author
|
Member
Author
|
Now that we've successfully unbroken hashing on master, I think this is ready to go. |
Member
|
For optimization 1, the OP is out of date, only Float16s are changed, not Float32s as well? I also don't see the speedup: julia> @btime sum(hash, reinterpret(Float16, typemin(UInt16):typemax(UInt16)));
224.000 μs (0 allocations: 0 bytes)
shell> git checkout more-hash-optimization -- base/float.jl base/gmp.jl base/rational.jl
julia> @btime sum(hash, reinterpret(Float16, typemin(UInt16):typemax(UInt16)));
223.333 μs (0 allocations: 0 bytes) |
Member
Author
|
Updated benchmarks. I agree that I'm not seeing much improvement for |
Member
|
If this doesn't provide measurable performance benefits, we should probably remove it: Lines 658 to 669 in 0a2d6fc |
This was referenced Jul 21, 2023
oscardssmith
added a commit
that referenced
this pull request
Jul 26, 2023
KristofferC
pushed a commit
that referenced
this pull request
Aug 10, 2023
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 is two separate optimizations.
The first is speeding up
hash(::Union{Float16, Float32})using the fact that they always are within the range ofInt64so you don't need to check that (or check whether they are within theUInt64range.The second is that
AbstractFloats andIntegers will never have a denominator that isn't 1, so we can change the rules of hashing to not hash the denominator if it is 1.