Repository navigation
bsi: vectorize and simplify batch equal with direct bitwise set operations - #532
Merged
guymolinari merged 2 commits intoJul 2, 2026
Merged
Conversation
…ross values
Follow-up addressing review findings on the vectorized implementation.
Correctness: the per-value path built results from bitplane clones and
never intersected eBM, so columns present in a plane but absent from
the existence bitmap leaked into results. The checked-in testdata/age
fixture contains exactly this state (plane 4 holds 33.3M bits against
28.0M in eBM): BatchEqual(0, {16}) returned 454,521 columns, all of
them outside eBM, where the pre-optimization implementation returned
none. GetValue, CompareValue, Sum, and the original BatchEqual all
treat eBM as authoritative; the new implementation is rooted in eBM by
construction, and a regression test pins the invariant.
Scaling: the maxVectorizedBatchSize=128 crossover was inverted on large
datasets. Measured on the age fixture, the vectorized path at M=128
cost 3.6s / 2.1GB while the scalar fallback it guarded cost 0.59s: the
guard fired on list size when the real variable is data size. Both
thresholds and the scalar fallback path are deleted.
BatchEqual now descends the bitplanes from the most significant bit as
a binary trie over the sorted, deduplicated query values: each shared
value prefix is intersected once, subtrees whose every bit pattern is
queried collapse to a single operation, and empty intermediates prune
the recursion. Work is bounded by the size of the values' bit trie and
the data actually present rather than len(values) x BitCount().
testdata/age fixture (28M columns, 8 planes), 16 threads, -benchmem,
previous commit -> this commit:
M=2 {55,57} ~56ms / 33.5MB / 10.3k allocs -> ~50ms / 26.7MB / 8.2k
M=128 contiguous 3.6s / 2.1GB -> 1.2ms / 9.3MB
M=128 scattered 3.3s / 2.2GB -> 440ms / 283MB
M=200 (fallback) 590ms / 155MB -> 3.3ms / 9.5MB
The M=2 delta is within run-to-run noise; allocation counts are exact.
New benchmarks cover both sides of the deleted thresholds and both
contiguous and scattered value shapes.
Contributor
Author
|
Pushed a follow-up commit (7fe6c1a) addressing review findings on the first version of this change:
Measured on the
The M=2 delta is within run-to-run noise; allocation counts are exact. The benchmark table in the PR description describes the previous commit; the benchmarks added in this commit cover both sides of the deleted thresholds and both contiguous and scattered value shapes. |
This was referenced Nov 4, 2026
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.
We present a vectorized implementation of BSI
BatchEqualusing direct bitwise set operations over the roaring bitmap bitplanes, replacing the per-column binary search scan. Across 10 samples under an AMD64 Linux environment (p ≈ 0.0000108), the primary metric is improved from 3,949,022,398 ns/op to 128,909,370 ns/op (a 96.7% speedup). Memory volume is reduced from 120,984,624 B/op to 33,492,618 B/op (a 72.3% decrease), and allocation count is reduced from 16,561.5 allocs/op to 10,341 allocs/op (a 37.6% decrease). There is no behavior change.Description
This pull request optimizes BSI
BatchEqualby implementing direct bitwise set operations (cloning and in-placeAnd/AndNotacross bitplanes, combined via sequentialOrorParOr), eliminating the per-column binary search overhead.Type of Change
Changes Made
What was changed?
BatchEqualimplementation to utilize vectorized operations directly over roaring bitmap bitplanes.Why was it changed?
GetValue, causingHow was it changed?
getEqualBitmaphelper to construct matching column sets directly via bitwiseAnd/AndNotoperations.Orfor smaller query sets orroaring.ParOrfor larger sets.Testing
Correctness claims are restricted to the following verified check:
go test -v ./BitSliceIndexing/...passed successfully.Performance Impact
Benchmark Results
Below are the measured benchmark metrics (n=10,$p \approx 0.0000108$ ):
Before:
BenchmarkBatchEqual-2 10 3949022398 ns/op 120984624 B/op 16561.5 allocs/opAfter:
BenchmarkBatchEqual-2 10 128909370 ns/op 33492618 B/op 10341 allocs/opProvenance Note:
The
baseline_commitnames the base revision (f3ceb59736b0acafd993fd6c622b9ac7cb105bd8) while the baseline arm was physically measured at the benchmark commit tree (base + benchmark), becausebenchmark_commitis true.Impact
This optimization benefits heavy BSI Batch Query Verification workloads where many values are queried simultaneously over high-cardinality indices. Reducing allocations and CPU usage directly translates to lower GC pressure and higher query throughput.
Reproduction
go test -json ./BitSliceIndexing -bench BenchmarkBatchEqual -run ^$ -benchmemlinux/amd64,go1.26.4on AMD EPYC 7B13 CPUf3ceb59736b0acafd993fd6c622b9ac7cb105bd875a6fca4f4f8773585e2fd77d9044bc5a6fc9cf7Limits
Alternatives Evaluated
Formatting
Fuzzing
Breaking Changes
Related Issues
Additional Notes
https://app.perfloop.ai/t/oss/case_0t48d3m05c
This is an automated, human-reviewed Perfloop contribution opened by perfloop-agent. The body links to reproducible proof for the change. The change was benchmarked on perfloop/roaring, an automation fork of roaringbitmap/roaring; the commit on this PR's head branch carries the proof.