Repository navigation
Add shrink_to_fit to RoaringBitmap and RoaringTreemap - #398
Open
emschwartz wants to merge 1 commit into
Open
emschwartz wants to merge 1 commit into
emschwartz wants to merge 1 commit into
Conversation
Intersections and differences size their result arrays for the inputs, so a small result can keep most of its input's capacity. shrink_to_fit frees that memory by shrinking the container vector and every array and run store, like CRoaring's roaring_bitmap_shrink_to_fit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Closes #136.
RoaringBitmap::shrink_to_fitshrinks the container vector and every array and run store to its length. Bitmap stores are fixed-size boxes, so there is nothing to shrink there.RoaringTreemap::shrink_to_fitcalls it on each bitmap and leaves empty partitions alone, since removing them isoptimize's job.The use case is the one @fjmaco measured on the issue: intersection and difference results keep the capacity of their inputs, so a 55,887-value intersection of two ~970K-value bitmaps holds 1,889 KiB of heap where a clone of it holds 119 KiB. Today that memory only comes back by rebuilding the bitmap, for example with
*bitmap = bitmap.clone(). CRoaring hasroaring_bitmap_shrink_to_fitfor the same reason. This version returns()rather than CRoaring's count of freed bytes, to behave likeVec::shrink_to_fit, which is what a Rust caller will expect from the name. fjmaco offered on the issue to write this too. Happy to close this if fjmaco's version is underway.Values and store kinds are unchanged. The one visible side effect is that
statistics().n_bytes_array_containersgoes down, since it is computed from capacity.Tested with new unit tests (an intersection that leaves slack in all three places, an emptied bitmap, a two-partition treemap) and doctests.
cargo mutantscatches all 5 mutants of the new functions.Authored with Claude (claude-opus-5-5).