I noticed while running the profiling for this post that GC#realloc was getting invoked during calls to Hash#resize, made while populating hashes that were created with an initial_capacity.
Here is a minimized repro:
class MyHash < Hash(Int32, Int32)
def resize : Nil
puts "Resizing, current_size: #{size}"
super
end
end
size = 1000
hash = MyHash.new(initial_capacity: size)
size.times { |i| hash[i] = i }
# => Resizing, current_size: 512
pp hash.size
# => 1000
Every hash size I've tested this against on current master calls resize, but it doesn't happen in 0.30.1 so it appears to be new behavior.
Good catch, thanks!
Perhaps there should also be a spec that resize is not immediately called like shown in this example
Most helpful comment
Good catch, thanks!