I used a 1MB array and applied map on it for some computation. It shows me an estimated allocation of 8MB. Can this happen or it’s some issue in reporting of BenchmarkTools package?
From pure intuition one can say the allocation should be the size of the input array. 8 times is a bit unlikely.
julia> @benchmark map(x -> 2x, arr)
BenchmarkTools.Trial:
memory estimate: 8.00 MiB
allocs estimate: 3
--------------
minimum time: 1.992 ms (0.00% GC)
median time: 2.309 ms (0.00% GC)
mean time: 2.592 ms (7.45% GC)
maximum time: 54.632 ms (93.92% GC)
--------------
samples: 1923
evals/sample: 1
Since arr is a global variable at the REPL, its type could change at any time. So using it in a benchmark will give misleading results because Julia also has to deal with the potential type-instability. You need to splice in the current value with $ like this: