Simplify slab partitioning with drain from end#1
Merged
NathanHowell merged 2 commits intofix/bulk-load-overcapacityfrom Feb 25, 2026
Merged
Simplify slab partitioning with drain from end#1NathanHowell merged 2 commits intofix/bulk-load-overcapacityfrom
NathanHowell merged 2 commits intofix/bulk-load-overcapacityfrom
Conversation
Instead of split_off + mem::replace + shrink_to_fit, invert the partition so slab elements end up at the tail and drain them into a new Vec with exact capacity. This eliminates the need for shrink_to_fit on every non-last slab while keeping the code simpler.
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
split_off+mem::replace+shrink_to_fitwith invertedpartition_envelopes+drainfrom the tailcollect(), eliminatingshrink_to_fiton the hot pathmem::take) needs shrinking sincedraindoesn't reduceself.remaining's capacitySuggested by @adamreichold in georust#220 (comment)
Test plan
test_cluster_group_iteratorupdated for reversed slab order (largest-first)test_cluster_group_iterator_no_excess_capacitycontinues to verify no over-allocationtest_bulk_load_no_excess_capacitycontinues to verify tree nodes aren't over-allocated