AxisArrays.jl icon indicating copy to clipboard operation
AxisArrays.jl copied to clipboard

Unexpected allocation on views of AxisArray

Open bgroenks96 opened this issue 5 years ago • 0 comments

Consider the following simple example:

const A = randn(100);
aa = AxisArray(A;x=SortedVector([i for i in 1:100]));
function axisarrays_alloc(array,xs)
           @view array[xs];
           nothing;
 end
xs = 2:10;
@benchmark axisarrays_alloc(aa,xs)

results in:

BenchmarkTools.Trial: 
  memory estimate:  352 bytes
  allocs estimate:  7
  --------------
  minimum time:     393.592 ns (0.00% GC)
  median time:      399.507 ns (0.00% GC)
  mean time:        443.488 ns (4.64% GC)
  maximum time:     15.236 μs (96.24% GC)
  --------------
  samples:          10000
  evals/sample:     201

This occurs if x is a SortedVector or plain Vector but not if it is a range. I believe this is related to #147 since the axes are being copied even in a view. I have not yet verified whether or not it is fixed by #148.

bgroenks96 avatar Jan 24 '21 14:01 bgroenks96