Conversation
Amanieu
reviewed
Sep 21, 2026
ywxt
force-pushed
the
btree_map_drop
branch
from
September 22, 2026 01:43
090dee9 to
011cd00
Compare
ywxt
force-pushed
the
btree_map_drop
branch
from
September 22, 2026 01:54
011cd00 to
61331d3
Compare
Abhirup0
reviewed
Sep 24, 2026
There was a problem hiding this comment.
I walked through the postorder traversal logic and panic safety guards across drop_kvs and drop_tree. The cleanup order and unwinding guarantees look solid:
drop_kvs's inner guard drops any remaining elements in the active node if a destructor panics, while the outer guard indrop_treeensures the remaining tree is traversed and deallocated without leaks.- Deallocating nodes in postorder right after their elements drop avoids all the
LazyLeafRangetracking overhead and matches the benchmarks well. - The
elsebranch inBTreeMap::dropproperly handles droppingself.allocwhenself.rootisNone.
Two minor non-blocking notes:
- In
library/alloc/src/collections/btree/node.rsline 448, the safety comment inDropGuard::dropmentionsidx < len, but the loop index isi. - In
library/alloc/src/collections/btree/node.rsline 438,drop_kvscould take&mut selfinstead of&selfto better reflect that it mutates and invalidates the node's element storage.
Nice work addressing the earlier feedback!
Contributor
|
☔ The latest upstream changes (presumably #163379) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
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.
When BTreeMap is dropping, it currently turns the tree into an iterator and traverses the kvs, updating the LazyLeafRange after each element is dropped. This is unnecessary during destruction. We can instead traverse the tree node by node and drop the kvs directly from each node.
Results on aarch64:
r? @Amanieu