Repository navigation
GH-45847: Pre-grow SwissTable to avoid repeated grow_double in map_new_keys - #53816
Open
Asthenia0412 wants to merge 1 commit into
Open
Asthenia0412 wants to merge 1 commit into
Asthenia0412 wants to merge 1 commit into
Conversation
…map_new_keys When GrouperFastImpl processes a minibatch where every row is a new key (common after a hash join scan emits rows with one unique key per payload), SwissTable::map_new_keys previously called grow_double() inside its do-while loop once per capacity threshold. Starting from log_blocks_=0 (8 slots), handling 1024 new keys required ~9 individual grow_double calls, each re-processing all existing entries, causing quadratic-ish overhead. This change pre-computes the required log_blocks capacity (mirroring num_groups_for_resize load factors: 50% for small tables, 75% for large) and performs all needed grow_double calls upfront when more than one is required. init_slot_ids_for_new_keys is called after the batched grow so slot ids are consistent with the new table size. All existing Grouper and hash aggregate tests still pass (83 row tests, 97 hash aggregate tests).
|
|
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.
Background
Issue #45847: Acero HashAggregate performs very poorly on multi-batch build scenarios (32+ batches). Performance drops 10x+ with only 1 CPU core utilized.
Root Cause
SwissTable::map_new_keysinkey_map_internal.ccstarts withlog_blocks_=0(8 slots) and callsgrow_double()each time capacity is exceeded. For N unique keys this causes O(log N) separate resize operations, each requiring O(N) re-insertion of ALL existing entries. With 2M unique keys from 64x32K batches, cascading resize dominates execution time.Solution
Pre-compute target capacity before the do-while loop and batch all grows at once:
log_blocks_so capacity >= num_inserted_ + num_idsnum_groups_for_resize)Changes: +44 lines, 0 deleted in
cpp/src/arrow/compute/key_map_internal.ccTesting
arrow-compute-row-test(Grouper): 83/83 PASSarrow-acero-hash-aggregate-test: 97/97 PASSarrow_compute_shared,arrow_acero_sharedcompile cleanlyFixes: #45847