Skip to content

Improve performance of sizehint! on BinaryHeap#907

Merged
oxinabox merged 4 commits intoJuliaCollections:masterfrom
ameligrana:patch-1
Apr 18, 2024
Merged

Improve performance of sizehint! on BinaryHeap#907
oxinabox merged 4 commits intoJuliaCollections:masterfrom
ameligrana:patch-1

Conversation

@ameligrana
Copy link
Contributor

@ameligrana ameligrana commented Apr 17, 2024

Noticed that sizehint! was actually worsening a lot of the performance of some of my heaps, with this change it is much faster:

e.g. with

using DataStructures, BenchmarkTools
function with_sizehint(T, n)
    value = BinaryHeap(Base.Order.ForwardOrdering(), T[])
    sizehint!(value, n)
end

before:

julia> @btime with_sizehint(Int, 1);
  861.250 ns (5 allocations: 256 bytes)

after:

julia> @btime with_sizehint(Int, 1);
  64.790 ns (4 allocations: 224 bytes)

@ameligrana
Copy link
Contributor Author

Oh actually 1.6 doesn't support @inline at callsite, so I will inline it in the definition

@oxinabox oxinabox merged commit 90e955b into JuliaCollections:master Apr 18, 2024
@oxinabox
Copy link
Member

oxinabox commented Apr 18, 2024

Great, I have back ported this also to 0.18.20
should be available in 10 minutes or so

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments