perf: speed up fresh Bitmap.Or sorted interleaved source-only high-key inserts#535
perf: speed up fresh Bitmap.Or sorted interleaved source-only high-key inserts#535perfloop-agent wants to merge 2 commits into
Conversation
…y inserts Signed-off-by: Perfloop Agent <agent@perfloop.ai>
| } | ||
|
|
||
| func (ra *roaringArray) orBulk(other *roaringArray, pos1, pos2 int) bool { | ||
| if !ra.checkKeysSorted() || !other.checkKeysSorted() { |
There was a problem hiding this comment.
@perfloop-agent That's odd here. The checkKeysSorted must return true. This function only exists to validate possibly malformed inputs when first loading the data structure. We don't have other operations check it.
There was a problem hiding this comment.
You're right, thanks. checkKeysSorted is a load-boundary check — it's only reached through Validate — and no other operation re-verifies it, so inside Or it can only ever return true. Dropped the call from the bulk path in 2db4d9c.
With it gone the fast path always applies, so the plumbing that existed only for its false branch is gone too: orBulk no longer returns a bool, the bulkMergeAvailable flag is removed, and the malformed-input fallback test is deleted. Or now trusts the sorted-key invariant like the forward path and every other operation; catching malformed input stays the caller's responsibility via Validate.
The union merge itself is unchanged (allocation profile on the interleaved fixtures is identical), and dropping the two key-array scans is neutral-to-slightly-faster on the bulk path.
checkKeysSorted is a load-boundary check reached through Validate; no operation re-verifies it, so inside Or it can only return true. Drop the call and the fallback plumbing that existed only for its false branch: orBulk no longer returns a bool, bulkMergeAvailable is gone, and the malformed-input fallback regression test is deleted. Or now trusts the invariant like the forward path and every other operation; malformed input stays the caller's responsibility via Validate.
Description
Speed up the measured fresh-receiver, sorted interleaved/source-only high-key insertion shapes in
Bitmap.Or, without changing the public API or intended bitmap semantics. No general latency improvement is claimed for the measured fresh-overlap, single-interior, or tail-adjacent shapes.Type of Change
Changes Made
What was changed?
Bitmap.Orhigh-key suffixes.Why was it changed?
How was it changed?
getUnionedWritableContainerpath and source-container COW/clone ownership rules.Testing
Recorded checks passed:
pairing,environment_consistent,baseline_valid,benchmark_passed,bulk-merge-semantics-and-ownership,bitmap-or-profile-boundary,all-go-packages,gofmt-simplify,unconvert,bulk-merge-tail-ownership-and-unordered-fallback,malformed-metadata-forward-fallback,measurements_sane,metric_present,sample_sufficiency, andsample_independence.The package-suite check was
go test -count=1 ./.... The focused semantic check wasgo test -count=1 -run '^TestBitmapOrBulkMerge' ..Formatting
The recorded
gofmt-simplifyandunconvertchecks passed.Fuzzing
Not run in this case; no fuzzing result is claimed as PR evidence.
Performance Impact
For the primary measured fresh-receiver 4,096-container sorted interleaved/source-only workload,
ns/opimproved from 6,864,674 to 999,185.5: 85.4445% lower, n=10 per arm, p=1.08251e-05.The benchmark fixture was authored for this case. The baseline was re-measured interleaved with candidate
8d782a0b121115c2b10a286024120b0e53ba71b7against44559cd5c0e01050eb7ee87feb73a1b6ee90cf43onlinux/amd64,go1.26.4,-cpu=1. Every entry below is a labelled baseline → candidate pair, with n=10 per arm.BenchmarkBitmapOrBulkMerge/fresh-append-only-4096— guardrail heldBenchmarkBitmapOrBulkMerge/fresh-copy-on-write-interleaved-4096— guardrail heldBenchmarkBitmapOrBulkMerge/fresh-interleaved-1024— guardrail heldBenchmarkBitmapOrBulkMerge/fresh-interleaved-4096— primaryns/opwon; allocation guardrails heldBenchmarkBitmapOrBulkMerge/fresh-interleaved-64— guardrail heldBenchmarkBitmapOrBulkMerge/fresh-interleaved-65— guardrail heldBenchmarkBitmapOrBulkMerge/fresh-overlap-4096— guardrail heldBenchmarkBitmapOrBulkMerge/fresh-single-interior-4096— guardrail heldBenchmarkBitmapOrBulkMergeTailAdjacent/fresh-single-interior-4096—ns/opunconfirmed; B/op and allocs/op guardrails heldSeven selector-level latency guardrails held. The tail-adjacent latency guard is unconfirmed and not statistically significant, rather than a claimed win or held guardrail. The primary workload's
B/opandallocs/opseries are guardrails; their before/after values are reported above, not presented as additional primary wins.Trade-off: the sorted fast path performs a sortedness validation before planned placement. If validation declines, the operation uses the existing forward path.
From a clean checkout with ordinary Go tooling, reproduce the primary native benchmark at each revision as follows:
Run the command ten times per worktree for the reported sample count.
Breaking Changes
Related Issues
Additional Notes
Implementation changes are in
roaring.goandroaringarray.go; focused semantic coverage and benchmark fixtures are inbitmap_or_bulk_merge_test.go,bitmap_or_bulk_merge_regression_test.go, andbitmap_or_bulk_merge_tail_adjacent_bench_test.go.Prior proof revisions
cand_e0zxpjxk2v(2f2d608433f840ff255aa009ce4d50534a4a6366) andcand_mee63wmm3f(a44478d8630cc6ded6d1eaa952a38237dda5b9d7) were inconclusive.cand_qnfnmn9d4z(ea59f145a1bdb72dfddc91aa210e027842eb60f1) andcand_9664d2j0de(c88ff333991cc76ae6072cc11cac5cd74a5e0c10) were validated proof-hardening revisions. The final candidate only clarifies the nested tail-adjacent benchmark leaf name while retaining the sealed compatibility selector.Full proof: https://app.perfloop.ai/t/oss/case_jyvmgdg1pq
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.
Assisted-by: PerfloopAgent:gpt-5.6-terra