DataStructures.jl icon indicating copy to clipboard operation
DataStructures.jl copied to clipboard

sizehint! ineffective for RobinDict

Open dantaras opened this issue 4 years ago • 1 comments

julia> function check_alloc(d, n)
           for i in 1:n
               a = @allocated d[i] = i
               println(i, " ", a)
           end
           nothing
       end
check_alloc (generic function with 1 method)

julia> check_alloc(sizehint!(RobinDict{Int, Int}(), 16), 16)
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 1584
14 0
15 0
16 0

The root cause is here https://github.com/JuliaCollections/DataStructures.jl/blob/f90dd8ceb1808123136d96599fbf41407ef4fadc/src/robin_dict.jl#L200-L201 which should instead be:

        resize!(h.keys, newsz)
        resize!(h.vals, newsz)

dantaras avatar Feb 09 '22 12:02 dantaras

Ah, my bad! Thanks for bring this to light @dantaras!

eulerkochy avatar Feb 09 '22 12:02 eulerkochy