Skip to content

[core] Keep the rbm32 and rbm64 union decoded between rows - #1568

Open
JeonDaehong wants to merge 2 commits into
apache:mainfrom
JeonDaehong:rbm-keep-decoded-union
Open

JeonDaehong wants to merge 2 commits into
apache:mainfrom
JeonDaehong:rbm-keep-decoded-union

Conversation

@JeonDaehong

@JeonDaehong JeonDaehong commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Closes #1567.

rbm32 and rbm64 deserialized and re-serialized the accumulated bitmap for every row, so a key with many rows took time quadratic in its bitmap size.

Brief change log

  • The accumulator keeps the first input as bytes. The second input decodes it once, and later inputs are unioned into the decoded bitmap.
  • result() serializes the union. A lone input is still returned unchanged.
  • In rbm64, a range list becomes a bitset once encoding would write it as one (more than 4096 values and at least 2048 runs), and a single incoming range is inserted in place.

Tests

keeps_a_lone_input_and_resets_the_union in both files checks that a lone Java input is returned byte for byte, that the union is right, and that reset clears it. merge_and_insert_ranges_match_sort_and_normalize compares the range merge with sort and normalize on random inputs, and two more tests check that the promoted bitset encodes to the same bytes.

Measured on c7i.8xlarge, release build, main and this branch alternated 3 times (ranges across runs). The output bytes hash the same on both for every shape.

Writing one commit through a table with rbm32:

rows main this PR
1 key × 100,000 7,053–7,066 ms 144–145 ms
100 keys × 1,000 204–205 ms 94 ms
100,000 keys × 3 288–291 ms 266–276 ms

Same with rbm64 (frag2 is every other value, as in the review):

rows main this PR
1 key × 32,768 (frag2) 278–279 ms 12 ms
1 key × 100,000 34,939–35,237 ms 27 ms
100 keys × 1,000 533–534 ms 33 ms
100,000 keys × 3 361–362 ms 334–345 ms

Aggregating directly, 1 key with N single-value bitmaps:

N rbm32 main rbm32 PR rbm64 main rbm64 PR
10,000 84 ms 10–11 ms 349 ms 1–2 ms
100,000 7,120–7,123 ms 116 ms 32,028–32,164 ms 20 ms

One input per key is unchanged (25–26 ms for 100,000 keys either way). Three inputs per key, 100,000 keys: rbm32 81 → 60 ms, rbm64 130–134 → 98–99 ms. Random values in one container (50,000 inputs) take 464 → 11 ms in rbm64.

API and Format

No public API or storage format changes.

Documentation

None.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the union decoded has clear value for high-cardinality aggregates. I ran 5,286 core and primary-key table tests on 57677458, including a new write, commit, scan, and compaction probe. The probe found a release-mode write latency regression for fragmented rbm64 inputs.

Entry::Vacant(vacant) => {
vacant.insert(container);
}
Entry::Occupied(mut occupied) => occupied.get_mut().union(container),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Promote fragmented rbm64 unions to a bitset as they grow. I wrote a single batch of 32,768 rows to one key in an aggregation table with fields.bitmap.aggregate-function=rbm64. Each row holds a singleton bitmap for (1 << 40) + 2 * i, so all values share a high-48-bit container and remain fragmented. Three release runs measured 177–190 ms for write through commit on e4b84b47 and 625–640 ms on this head. The union bytes matched before and after compaction.

On main, intermediate encoding promotes fragmented containers to bitsets, which the next union decodes as Words. With the decoded accumulator, each singleton stays on Ranges::union and sorts and scans the growing range list. Please promote dense, fragmented ranges in memory using the same size threshold as encoding, and include this input shape in the benchmark.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @JingsongLi, reproduced it with your shape: 914–922 ms on the previous head, 278–279 ms on main (write through commit, 3 runs). A range list now turns into a bitset as soon as encoding would write it as one (more than 4096 values and at least 2048 runs), and a single incoming range is inserted in place instead of re-sorting the whole list. Your shape takes 12 ms now. I added it to the benchmark along with runs of three values and random values in one container, and the output bytes match main for every shape. Updated numbers are in the description (14b0d6d).

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.

rbm32 and rbm64 aggregation re-serialize the bitmap for every row

2 participants