A bug in using varinfo() when there is 3d data in the struct structure!

To my understanding there isn’t. Rather

data3d::Array{AbstractFloat, 3}

is saying the array should be expected to be of mixed element type, and it is stored as such, basically as an array of pointers to each element. Thus sending varinfo on a wild chase around memory, and is absolute poison for performance in general.

Unless you truly need to store different floating point formats in that matrix, this is not what you want. Try either

mutable struct Block3d
    data2d::Matrix
    data3d::Array{<:AbstractFloat, 3}
end

julia> bloct2=Block3d(zeros(80,20000),zeros(80,200,200));

julia> @time varinfo(r"bloct2")
  0.000057 seconds (61 allocations: 3.914 KiB)
  name         size summary
  –––––– –––––––––– –––––––
  bloct2 36.621 MiB Block3d

or introduce a type parameter

mutable struct Block3d{T<:AbstractFloat}
    data2d::Matrix{T}
    data3d::Array{T, 3}
end

PS: Please avoid double posting (Using varinfo() very slow when there is 3d data in the struct structure). This post already attracted attention. Title and category can still be changed after submission.

2 Likes