I don´t know. Seems to be some artifact of benchmarking? In a “real” test it does not allocate:
julia> using ChunkSplitters
julia> x = rand(1000);
julia> function test(x)
s = 0.0
for inds in chunks(x; n = 100)
for i in inds
s += x[i]
end
end
return s
end
test (generic function with 1 method)
julia> test(x)
509.1937895395777
julia> @btime test($x)
716.511 ns (0 allocations: 0 bytes)
509.1937895395777
One difference, relative to the benchmark, is that in the “real” test the return value of the function to the REPL is always of the same type, while in the small example it can return nothing to the REPL. That may cause an artificial allocation, maybe.
You could try to slap a @inline in front of your iteration functions. Sometimes that fixes allocations (which might stem from tuple packing/unpacking or so…)
This is what I thought at first, but iterate(x::Vector) does not allocate, even if it can return nothing. So it seems that inlining definitely has also to do with it…