Skip to content

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

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

Metadata

Metadata

Assignees

Labels

A-collectionsArea: `std::collections`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