In the following example, I am passing a set of subscripts i, j, k
of a 3-dimensional array A
in the form of vector v = [i,j,k]
or tuple t = (i,j,k)
using a splat ...
. I find that A[v...]
uses 2 allocations whereas A[t...]
doesn’t. This leads to much slower execution of A[v...]
compared to A[t...]
:
julia> VERSION
v"0.7.0-DEV.82"
julia> using BenchmarkTools
julia> v = [1,2,3]; t = (1,2,3); A = rand(3,3,3);
julia> @btime $A[$v...]
81.003 ns (2 allocations: 32 bytes)
0.9645012234582633
julia> @btime $A[$t...]
2.266 ns (0 allocations: 0 bytes)
0.9645012234582633
Why does v...
need to use allocations? Is this something that can be fixed, or there is something fundamental in vectors that requires allocations?