Skip to content

Optimize BTreeMap::append() using CursorMut#153107

Open
asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215:btreemap_append_optimized
Open

Optimize BTreeMap::append() using CursorMut#153107
asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215:btreemap_append_optimized

Conversation

@asder8215
Copy link
Contributor

@asder8215 asder8215 commented Feb 25, 2026

Since BTreeMap::merge uses CursorMut to avoid reconstructing the map from scratch and instead inserting other BTreeMap at the right places or overwriting the value in self BTreeMap on conflict, we might as well do the same for BTreeMap::append. This also means that some of the code in append.rs can be removed; bulk_push() however is used by bulk_build_from_sorted_iterator(), which is used by the From/FromIterator trait impl on BTreeMap. Feels like we should rename the file or place the bulk_push() in an existing file.

The same additional optimization consideration that BTreeMap::merge has is also applied to BTreeMap::append.

r? @Mark-Simulacrum since Mark has seen the BTreeMap::merge code already (only diff is the Ordering::Equal case and now one of the test assertions on a panic case has the correct value now).

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 25, 2026
@asder8215
Copy link
Contributor Author

asder8215 commented Feb 25, 2026

I'd be curious to see if this shows any noticeable performance difference with the current implementation of BTreeMap::append

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants