Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hash index split slot ID when reserving a number of slots which are a power of two #3066

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

benjaminwinger
Copy link
Collaborator

E.g.
When reserving 64 slots, numSlotsOfCurrentLevel will be 32 instead of 64, and the nextSplitSlotId will be 32, instead of 0.

This shouldn't cause any issues, but the behaviour wasn't what I was expecting and it does some unnecessary work.

  1. Since the levelHashMask is 31, all slots calculated using it will be less than the nextSplitSlotId (in getPrimarySlotIdForHash) and use the higherLevelHashMask (which is the same if we had instead increased the level by one and reset nextSplitSlotId to 0).
  2. The first time splitSlot is called it will split slot 32, but entries used the higherLevelHashMask when inserting into it originally, so all the entries get hashed back into the same slot, and then the level will be incremented and nextSplitSlotId will be reset to 0.

(Also added a missing include that's necessary with newer versions of gcc because <string> no longer implicitly includes it)

Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.03%. Comparing base (c3556e2) to head (2a3012c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3066   +/-   ##
=======================================
  Coverage   93.02%   93.03%           
=======================================
  Files        1153     1153           
  Lines       43220    43221    +1     
=======================================
+ Hits        40207    40211    +4     
+ Misses       3013     3010    -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ray6080
Copy link
Contributor

ray6080 commented Mar 17, 2024

Nice catch on this!

@benjaminwinger benjaminwinger merged commit 826927e into master Mar 18, 2024
17 checks passed
@benjaminwinger benjaminwinger deleted the hash-index-reserve-fix branch March 18, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants