Skip to content

Use multiply to calculate hashtable index faster#816

Open
mmozeiko wants to merge 1 commit into
EpicGames:devfrom
mmozeiko:faster_hash_index
Open

Use multiply to calculate hashtable index faster#816
mmozeiko wants to merge 1 commit into
EpicGames:devfrom
mmozeiko:faster_hash_index

Conversation

@mmozeiko

@mmozeiko mmozeiko commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

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 % count to ((U128)hash * count) >> 64 calculation - 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 % count but 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_pdb and linker folders, 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.

@mmozeiko mmozeiko force-pushed the faster_hash_index branch from 0148be9 to 32ee02a Compare June 25, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant