rust-lang / rust-lang/rust

Making and dropping an empty `BTreeMap` is not free.

Open
#161,375 3 comments 0 reactions 1 assignee View on GitHub

@jakedrew is already working on this.

Since Aug 19, 2026.

A-collections C-optimization S-has-bisection T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.