Why is garbage collection so much slower when a large number of mutable structs are loaded in memory as compared with non-mutable structs? The object tree should have the same size in both cases.
julia> struct Foo
a::Float64
b::Float64
c::Float64
end
julia> mutable struct Bar
a::Float64
b::Float64
c::Float64
end
julia> @time dat1 = [Foo(0.0, 0.0, 0.0) for i in 1:1e9];
9.706709 seconds (371.88 k allocations: 22.371 GiB, 0.14% gc time)
julia> @time GC.gc(true)
0.104186 seconds, 100.00% gc time
julia> @time GC.gc(true)
0.124675 seconds, 100.00% gc time
julia> @time dat2 = [Bar(0.0, 0.0, 0.0) for i in 1:1e9];
71.870870 seconds (1.00 G allocations: 37.256 GiB, 73.88% gc time)
julia> @time GC.gc(true)
47.695473 seconds, 100.00% gc time
julia> @time GC.gc(true)
41.809898 seconds, 100.00% gc time