[improve][broker] Optimize bucket delayed-delivery bitmap point operations#26205
Merged
Conversation
dao-jun
approved these changes
Jul 17, 2026
void-ptr974
reviewed
Jul 18, 2026
void-ptr974
left a comment
Contributor
There was a problem hiding this comment.
Nice optimization for the point operations.
In remove(from, to), removesSinceTrim now only increases by 1 even when the range removes many values. This does not affect correctness, but it can delay trim() and retain extra bitmap memory longer for large non-empty range removals.
Please keep accounting by the removed count instead.
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.
Motivation
The bucket delayed-delivery code was using range-overload bitmap operations to manipulate individual entries —
add(entryId, entryId + 1),remove(entryId, entryId + 1),contains(entryId, entryId + 1). These are semantically equivalent to the single-value overloads (half-open[v, v+1)contains exactlyv, verified at the RoaringBitmap 1.6.9 source level), but incur unnecessary overhead: range validation, half-open arithmetic, and iteration setup.Bucket.removeIndexBitwas the more impactful case — it calledcontains(v)thenremove(v)separately, acquiring twoStampedLocks (read then write) and traversing the RoaringBitmap twice per ack. Theremove(v)return value can carry the "was present" signal in a single atomic operation, eliminating the redundant lookup.Modifications
LongBitmap/ConcurrentRoaringBitmap:remove(long)andremove(long, long)now returnboolean, mirroring the existingcheckedAddpattern. Single-value usesMutableRoaringBitmap.checkedRemove; range uses cardinality diff to compute the boolean return and only bumpsremovesSinceTrimwhen something was actually removed (previously it bumped by the range upper bound unconditionally).Bucket: All point operations switched to single-value overloads.removeIndexBitnow uses the boolean return fromremovedirectly, eliminating the redundantcontainscheck — saving oneStampedLockacquisition and one RoaringBitmap container lookup per ack on the delayed-delivery hot path.MutableBucket: Snapshot-build path switched fromadd(entryId, entryId + 1)toadd(entryId).Performance
Local JMH measurement on
LongBitmapBenchmark(single-threaded, point-remove pattern with bitmap size 1k and 100k) shows ~22–27% throughput improvement forremovereturning boolean vscontains + remove:contains + removeremove(boolean)