Hello, I have the following example of a custom array and I do not know why there is a nearly factor 2 overhead in the performance for my custom array type MyArray
using BenchmarkTools
struct MyArray{T,N} <: AbstractArray{T,N}
A::Array{T,N}
end
Base.size(A::MyArray) = size(A.A)
Base.getindex(A::MyArray, i::Int) = getindex(A.A, i)
Base.setindex!(A::MyArray, v, i::Int) = setindex!(A.A, v, i)
Base.IndexStyle(::Type{<:MyArray}) = IndexLinear()
A = rand(1000, 1000)
B = MyArray(rand(1000, 1000))
@btime sum(A)
@btime sum(B)
This results in
1.368 ms (1 allocation: 16 bytes)
2.016 ms (1 allocation: 16 bytes)
This was exactly the missing part. Now the time is the same. Considering how often one simply wraps an array to have a dispatch on custom types, maybe there should be a note on this in the Interface documentation…