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

**URL:** <https://discourse.julialang.org/t/a-bug-in-using-varinfo-when-there-is-3d-data-in-the-struct-structure/104449>\
**Category:** Performance\
**Tags:** question, base\
**Created:** [October 1, 2023, 3:07am UTC](https://discourse.julialang.org/t/a-bug-in-using-varinfo-when-there-is-3d-data-in-the-struct-structure/104449 "2023-10-01T03:07:51Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [October 1, 2023, 9:48am UTC](https://discourse.julialang.org/t/a-bug-in-using-varinfo-when-there-is-3d-data-in-the-struct-structure/104449/4 "2023-10-01T09:48:38Z")

</div>

> [@13299118606](#):
>
> There is a bug in using varinfo when there is three-dimensional 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

```julia
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

```julia
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](https://discourse.julialang.org/t/using-varinfo-very-slow-when-there-is-3d-data-in-the-struct-structure/104454)). This post already attracted attention. Title and category can still be changed after submission.

---

_[View the full topic](https://discourse.julialang.org/t/a-bug-in-using-varinfo-when-there-is-3d-data-in-the-struct-structure/104449)._
