Closed
Description
As discussed in the corresponding Discourse topic, Base.summarysize
accounts the union optimization byte twice. Copying from the discussion:
julia> sizeandsummary(x) = sizeof(x), Base.summarysize(x)
julia> 1:100 |> Memory{UInt8} |> sizeandsummary
(100, 116)
julia> 1:100 |> Memory{Union{Nothing,UInt8}} |> sizeandsummary
(200, 316)
Where the last number should be 216, not 316.
The relevant code in summarysize.jl
is as follows
dsize = sizeof(obj)
T = eltype(obj)
if isbitsunion(T)
# add 1 union selector byte for each element
dsize += length(obj)
end
The line dsize = sizeof(obj)
accounts for the union byte array (see above). As Union{Nothing, UInt8} |> Base.isbitsunion
(unsurprisingly) returns true
, the union byte array is accounted a second time in dsize += length(obj)
.