Skip to content

Unexpected allocation on views of AxisArray #191

@bgroenks96

Description

@bgroenks96

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions