Use multiply to calculate hashtable index faster#816
Open
mmozeiko wants to merge 1 commit into
Open
Conversation
0e0ca5a to
e3e1b11
Compare
e3e1b11 to
9acca6e
Compare
9ccefcd to
c6a4e4c
Compare
9acca6e to
0148be9
Compare
0148be9 to
32ee02a
Compare
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.
Change how hashtable index is calculated from 64-bit hash - instead of slow division operation use a much faster single multiply operation.
This changes
hash % countto((U128)hash * count) >> 64calculation - but shift will be no-op, as high 64-bit value of 128-bit multiplication result will be in its own register.It will calculate different value than
hash % countbut it will still be distributed reasonably uniformly in[0, count)interval.This works because you can pretend hash value is 0.64 fixed-point value representing
[0, 1)float. Thus multiplying it with integer N will give you value in[0, N)interval.I did not change files in
codeview_parse,dwarf_parse,rdi_parse,rdi_make,rdi_from_dwarf,rdi_from_pdbandlinkerfolders, because I'm not sure in which places hash table contents depends on actual % operation result in rdi/dwarf/pdb file formats. Probably bunch of places there also can be changed to use this faster way.