vcat with splatting does not suffer from this problem
a=rand(1:10, rand(1:10))
b=rand(1:10, rand(1:10))
c=rand(1:10, rand(1:10))
d=rand(1:10, rand(1:10))
e=rand(1:10, rand(1:10))
f=[]
x=[a,b,c,d,f,e]
vcat(x...)
y=[f,a,b,c,d,e,f]
Base.splat(vcat)(y)
even in terms of performance it does well
v=[rand(1:10, rand(0:10)) for _ in 1:100]
using BenchmarkTools
julia> @btime vcat(v...);
873.684 ns (1 allocation: 4.06 KiB)
julia> @btime reduce(vcat, v, init=Int[]);
19.600 μs (102 allocations: 206.09 KiB)
julia> vcat(v...)==reduce(vcat, v, init=Int[])
true
if you notice the number of allocations of Base.splat(vcat)
is always 1 up to vectors with 256 elements. While that of reduce(vcat)
is equal to the size of the vector v + 2
julia> v=[rand(1:10, rand(0:10)) for _ in 1:256]
256-element Vector{Vector{Int64}}:
[8, 4, 8, 1, 1, 9]
[4, 8, 6, 8, 10, 8, 6, 9, 4]
[2, 3, 10, 5, 2]
[6]
[2, 3]
[5, 4]
...
[8, 4, 4, 10, 9, 1]
[5]
[8, 9]
[3, 10, 9, 3, 3, 6, 9, 1, 9]
[]
julia> @btime vcat(v...);
2.044 μs (1 allocation: 9.94 KiB)
julia> @btime reduce(vcat, v, init=Int[]);
120.400 μs (258 allocations: 1.29 MiB)