Repository navigation
HollowSparseIntegerSet: skip the clone and CAS when set()/clear() would not change the bit - #872
Merged
Sunjeet merged 1 commit intoOct 14, 2026
Conversation
…ld not change the bit SparseBitSet.set() and clear() cloned the bucket's long[] on every call, before checking whether the bit actually needed to change, and then always CASed a new Bucket into place. Setting a bit that is already set, or clearing one that is already clear (for a long that is initialized), therefore allocated a copy of the bucket and replaced it with an identical one. Check the bit against the published long[] first and return early when it is already in the target state. Published arrays are never mutated, so the clone now happens only on the paths that update an existing long in place; the paths that grow or shrink the array already build a new one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
@jasonk000 this is the separate PR related to the comment from #871 (comment) |
Sunjeet
approved these changes
Oct 14, 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.
Summary
SparseBitSet.set()andclear()cloned the bucket'slong[]before checking whether the bit actually needed to change, and then always CASed a newBucketinto place. Re-setting a bit that is already set, or clearing one that is already clear, allocated a copy of the bucket and swapped in an identical one.This is the same pattern as the
ThreadSafeBitSet.set()/clear()fix, kept as a separate PR.long[]first and return early when it is already in the target state, skipping both the clone and the CAS.Testing
testSetAndClearAreIdempotent: repeated set/clear of bits that share a long and a bucket, including clearing unset bits in an initialized long.testRepeatedSetAndClearMultipleThread: threads concurrently re-set every value, then concurrently re-clear the odd values, and the test checks the final contents.SparseBitSetTest(10) andHollowSparseIntegerSetTest(2) pass.🤖 Generated with Claude Code