fix: correct operator precedence in DDict hashset load factor check - #4760
Open
VirajMishra1 wants to merge 1 commit into
Open
fix: correct operator precedence in DDict hashset load factor check#4760VirajMishra1 wants to merge 1 commit into
VirajMishra1 wants to merge 1 commit into
Conversation
The load factor expansion check evaluates as ((count * 4) / size) * 3 due to left-to-right associativity, triggering expansion at ~25% load instead of the intended 75% (count * 4 / (size * 3)). This causes the hashset to grow ~3x faster than necessary. Add parentheses to match the formula documented in the comment.
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.
The DDict hashset load factor check in
ZSTD_DDictHashSet_expandhas an operator precedence bug. The intent (documented in the comment at lines 83-87) is to check whethercount * COUNT_MULT / (size * SIZE_MULT) != 0, i.e. whether the load factor exceeds 0.75.But the expression lacks parentheses around the denominator:
Due to left-to-right associativity of
*and/, this evaluates as((count * 4) / size) * 3instead ofcount * 4 / (size * 3). This triggers expansion at ~25% load instead of the intended 75%, causing the hashset to grow ~3x faster than necessary.Fix: add parentheses around the denominator to match the documented formula.