fix: Concatenate chunk bitmaps in a single pass - #223
Open
SamuelSchlesinger wants to merge 2 commits into
Open
Conversation
concatManyColumns concatenates the data in one VB.concat, but the
nullable path folds the per-chunk bitmaps pairwise and carries the
running length by concatenating the data vectors again at every step:
concatBms ((b1, v1) : (b2, v2) : rest') =
let merged = go b1 (VB.length v1) b2 (VB.length v2)
in concatBms ((merged, v1 <> v2) : rest')
That reinstates the accumulator recopy the function exists to avoid.
Allocation grows 15x for 4x the rows where linear would be 4x.
The second case is an oracle rather than a repro: uneven chunks that
straddle byte boundaries must keep every value and null position, which
is the property the new bitmap writes have to preserve.
The nullable path folded the per-chunk bitmaps pairwise and concatenated the data vectors on every step just to carry a running length, so it recopied the accumulator exactly the way the function's one-pass design sets out to avoid. Take the lengths up front and splice every chunk's bits into one preallocated destination with concatValidity, the byte-level splice the Bitmap module already has. For 160 chunks of 10k nullable rows: allocation growth drops from 15x to 4x per 4x the rows, and forcing the bitmap from 449ms to 7.9ms.
SamuelSchlesinger
force-pushed
the
fix/concat-many-columns-linear
branch
from
August 25, 2026 08:36
41267d5 to
4a8209c
Compare
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 nullable path of
concatManyColumnsfolded the per-chunk bitmaps pairwise and re-concatenated the data vectors at each step just to carry a running length, so it recopied the accumulator — the thing the function exists to avoid. UseconcatValidityinstead.160 chunks of 10k nullable rows: forcing the bitmap goes from 449ms to 7.9ms. The test pins values and null positions across uneven chunks and checks allocation grows linearly.