Skip to content

GH-45847: Pre-grow SwissTable to avoid repeated grow_double in map_new_keys - #53814

Closed
Asthenia0412 wants to merge 1 commit into
apache:mainfrom
Asthenia0412:perf/acero-swisstable-multi-batch
Closed

Asthenia0412 wants to merge 1 commit into
apache:mainfrom
Asthenia0412:perf/acero-swisstable-multi-batch

Conversation

@Asthenia0412

@Asthenia0412 Asthenia0412 commented Oct 14, 2026 •

Copy link
Copy Markdown

Background

Issue #45847: Acero HashAggregate performs very poorly on multi-batch scenarios with the build side (32+ batches). Performance drops 10x+ and only 1 CPU core is used.

Problem

SwissTable::map_new_keys in key_map_internal.cc starts with log_blocks_=0 (8 slots) and calls grow_double() each time capacity is exceeded. For N unique keys this causes O(log N) separate resize operations. With 2M unique keys from 64x32K batches, cascading resize dominates execution time.

Solution

Pre-compute target capacity before the do-while loop and perform all needed grows in one batch. Small tables use 50% load factor, large tables use 75% (matching num_groups_for_resize). If multiple grows needed, bulk-resize once.

Changes: +44 lines, 0 deleted in key_map_internal.cc

Testing

  • Existing arrow-compute-row-test (Grouper): 83/83 PASS
  • Existing arrow-acero-hash-aggregate-test: 97/97 PASS
  • Build: arrow_compute_shared, arrow_acero_shared both compile cleanly

Fixes: #45847

…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).
@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

This pull request has been automatically closed because you currently have 4 open pull requests, which is more than the limit of 3.

Due to the increase in pull requests opened by AI bots, and in order to keep the review queue manageable, Apache Arrow limits contributors without repository access to at most 3 concurrently open pull requests. This helps make sure each pull request gets the attention it needs and that work in progress does not go stale.

Once one of your other open pull requests has been merged or closed, you are welcome to reopen this one.

See also:

@github-actions github-actions Bot closed this Oct 14, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #45847 has been automatically assigned in GitHub to PR creator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][Compute][Acero] Poor aggregate performance when there is a large number of batches on the build side

1 participant