Repository navigation
Never keep a run container with more than 2047 runs - #607
Merged
Merged
Conversation
A run container with 2048 runs or more serializes to more than the 8192 bytes of a bitmap container, and the other Roaring implementations never produce one. The Go library could: or, iaddRange, iremoveRange and not returned run containers without checking their size, and toEfficientContainer compared against bitmapContainerSizeInBytes() (8224 bytes, including in-memory overhead), so it kept up to 2055 runs. Add maxRunsInRunContainer (2047) and a cheap limitRuns check that turns an oversized run container into an array or bitmap container. Apply it to the operations that could grow a run container unchecked, and make the run/array/bitmap toEfficientContainer functions refuse to return a run container past the limit. Update tests that relied on the old behavior: hardcoded checksums of bitmaps that are now bitmap containers instead of 2048-run containers, a test that grew a run container to 32768 runs with RemoveRange, and a test that dropped the result of iaddRange.
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.
A run container with 2048 runs or more serializes to more than the 8192 bytes of a bitmap container. CRoaring and Java never produce one, but this library could:
runContainer16.or(run ∪ run),iaddRange,iremoveRangeandnotreturned run containers without any size check. For example, removing every other value of a full container withRemoveRangebuilt a run container with 32768 runs (about 128 KiB instead of 8 KiB).toEfficientContainer(run, array and bitmap versions) compared againstbitmapContainerSizeInBytes(), which is 8224 bytes because it includes in-memory overhead. As a result it kept run containers with up to 2055 runs.Change
maxRunsInRunContainer = 2047and(*runContainer16).limitRuns(). It is a length check and converts to an array container (≤ 4096 values) or a bitmap container only when the limit is exceeded.limitRuns()fromor(run case),iaddRange,iremoveRangeandnot.inot,ior,andNotandiandNotalready go throughtoEfficientContainer.toEfficientContainer/toEfficientContainerFromCardinalityon run, array and bitmap containers no longer return a run container with more than 2047 runs.Validateis unchanged: serialized bitmaps with more runs (written by earlier versions) are still accepted.Tests
runcontainer_maxruns_test.gocovers the limit at the container level (or, ior, lazyOR, iaddRange, iadd, iremoveRange, iremove, not, inot, andNot, iandNot, and everytoEfficientContainer) and at the bitmap level (Or, in-placeOr,FastOr,AddRange,Add,Flip,RemoveRange). Several of these fail without the fix.TestHash: three expected checksums (N=4095/4096/4097, gap=32, part 2) changed, because those bitmaps are now stored as bitmap containers instead of 2048-run containers.Checksumdepends on container type.TestRunOptimizeRecoversSpaceAfterRemoveRange(root and roaring64) relied onRemoveRangebuilding a 32768-run container. It is nowTestRemoveRangeDoesNotGrowRunsPastBitmapSize, which checks that this no longer happens.TestBitmapContainerIAndNotdropped the result ofiaddRange. That only worked while the receiver stayed a run container that grew in place.TestBitmapContainerToEfficientContainerChoice: its reference rule now includes the run limit.