fix: account for initial hash table allocation in ArrowBytesMap/ArrowBytesViewMap#21249
Open
yashrb24 wants to merge 3 commits intoapache:mainfrom
Open
fix: account for initial hash table allocation in ArrowBytesMap/ArrowBytesViewMap#21249yashrb24 wants to merge 3 commits intoapache:mainfrom
yashrb24 wants to merge 3 commits intoapache:mainfrom
Conversation
…BytesViewMap ArrowBytesMap and ArrowBytesViewMap initialize their hash table with with_capacity(INITIAL_MAP_CAPACITY) but set map_size to 0. The insert_accounted method only tracks incremental growth beyond the current capacity, so the initial allocation is never counted in size() — understating memory usage. Initialize map_size with map.allocation_size() to capture the pre-allocated memory.
03429d9 to
0673088
Compare
Verify that ArrowBytesMap::size() and ArrowBytesViewMap::size() account for the hash table memory pre-allocated by HashTable::with_capacity(). Both tests fail without the fix (map_size: 0) and pass with it.
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.
Which issue does this PR close?
Rationale for this change
ArrowBytesMapandArrowBytesViewMapallocate their hash tables withHashTable::with_capacity(INITIAL_MAP_CAPACITY)but initializemap_sizeto0. Theinsert_accountedmethod only tracks incremental growth beyond the current capacity, so the initial allocation fromwith_capacityis never counted.size()understates memory usage until the first resize.What changes are included in this PR?
Initialize
map_sizewithmap.allocation_size()in bothArrowBytesMap::newandArrowBytesViewMap::newto capture the pre-allocated memory.Are these changes tested?
The change is a one-line init fix. Existing tests cover the
size()method behavior.Are there any user-facing changes?
No API changes.
size()now returns the memory estimate that includes the initial hash table allocation.