The following program allocates memory (according to the @time macro) proportionally to n, which suggests that each invocation of tuple creates something on the heap. Note that the program is written so that the length of the tuple is known at compile time, and hence, in principle, it should be possible to allocate the tuple on the stack. Is there a different technique to create a fixed-length tuple without heap allocation? I think I might be able to solve this problem with a generated function, but maybe something simpler is available?
module test_memtup
function sumtup(j, ::Val{N}) where N
v = tuple(((j + i) for i=1:N)...)
sm = 0
for k = 1 : N
sm += v[k]
end
sm
end
function test(n)
N = 6
s = 0
for k = 1 : n
s += sumtup(k, Val{N}())
end
s
end
end