Array of functions and allocation

Because Function is an abstract type. If you use a tuple, performance is back:

julia> ft = (f1,)
(f1,)

julia> @btime $ft[1]($u,$v)
  0.016 ns (0 allocations: 0 bytes)
0.7

because

julia> typeof(ft)
Tuple{typeof(f1)}

(also note that you should benchmark the vector with @btime $fv[1]($u,$v))

4 Likes