This also has overhead, more than the Tuple example it seems:
julia> function f()
x = 1
@show_locals
end
f (generic function with 1 method)
julia> f()
Individual sizes (does not account for overlap):
x: 8 bytes
Joint size: 472 bytes
It’s negligible when your instances are large enough to take up most of the reported memory, like your example with a 100x100 matrix, but that’s not always the case. I’m not sure if there is a way to separate the memory of the values
iterator and the referenced @locals
dictionary from the memory of the contained instances, though. sizeof(locals)
is a constant for any size, so probably have to dig into some internals.
@locals
makes a Dict{Symbol, Any}
, so it would involve how those instances are boxed. Hypothetically the boxes on the heap could just point to the existing instances, but I don’t actually know how boxes are implemented; as far as I know, copying could happen for many immutables. In any case, @locals
or any other container would only contain 1 of the copies, so summarysize
wouldn’t count twice.