Skip to content

Making and dropping an empty BTreeMap is not free. #161375

Closed

Description

@ruriww

I tried this code:
https://godbolt.org/z/v594PEsr7

I expected to see this happen:

ret

Instead, this happened:

example[7a9efb3d937417e2]::drop_btree:
        push    r14
        push    rbx
        sub     rsp, 104
        mov     qword ptr [rsp + 32], 0
        mov     qword ptr [rsp + 64], 0
        mov     qword ptr [rsp + 96], 0
        lea     rdi, [rsp + 8]
        lea     rsi, [rsp + 32]
        call    <alloc[c00562a4ff4db933]::collections::btree::map::IntoIter<(), ()>>::dying_next
        cmp     qword ptr [rsp + 8], 0
        je      .LBB0_3
        lea     rbx, [rsp + 8]
        lea     r14, [rsp + 32]
.LBB0_2:
        mov     rdi, rbx
        mov     rsi, r14
        call    <alloc[c00562a4ff4db933]::collections::btree::map::IntoIter<(), ()>>::dying_next
        cmp     qword ptr [rsp + 8], 0
        jne     .LBB0_2
.LBB0_3:
        add     rsp, 104
        pop     rbx
        pop     r14
        ret

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 19, 2026
  2. added
    C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing such
    and removed
    C-bugCategory: This is a bug.
    on Aug 19, 2026
  3. jakedrew commented on Aug 19, 2026

    @jakedrew
    Contributor

    @rustbot claim

  4. jakedrew commented on Aug 19, 2026

    @jakedrew
    Contributor

    Regression introduced in 7b28036 in 1.56.0.
    Testing same code in 1.55.0 produces the expected result: https://godbolt.org/z/Y5bnKe7jW

  5. added
    A-collectionsArea: `std::collections` (prefer A-binaryheap, A-btree, A-hashtable, A-linkedlist, A-vecdeque)
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 20, 2026
  6. bardiharborow commented on Aug 24, 2026

    @bardiharborow
    Contributor

    @rustbot label +S-has-bisection

  7. added a commit that references this issue on Sep 26, 2026
  8. added a commit that references this issue on Sep 26, 2026
  9. added
    A-btreeArea: `std::collections::{BTreeMap, BTreeSet}`
    and removed
    A-collectionsArea: `std::collections` (prefer A-binaryheap, A-btree, A-hashtable, A-linkedlist, A-vecdeque)
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-btreeArea: `std::collections::{BTreeMap, BTreeSet}`C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchS-has-bisectionStatus: A bisection has been found for this issueT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions