Array of functions - is there a way to avoid allocations performance penalty?

Many thanks, all. I am new to Julia and not a programmer by trade so it is a steep learning curve. I do now have a solution that appears to work (below) and am investigating others.

I have started to investigate the Dict approach mentioned above. My early efforts found that iterating through a Dict produces the same memory allocation as looping through arrays or tuples, but I did not use metaprogramming. I am reading about FunctionWrappers but don’t fully understand it yet. The “using type for dispatch” and the “tuple of structs” approaches mentioned above sound like they would provide maximum flexibility and I will learn how to use them.

As for the short term, what I have learned is that unrolling the inner loop (as suggested by the timings above) avoids the large excessive memory allocations that looping through a tuple or array requires. The code below does this, and runs a fair amount faster (1/3 time) than the not-unrolled loop, in my simple example of looping through only 2 functions. It also does not require a lot of hard (for me) to read code. So I have a workable solution I can use while I learn more about Julia.

using Unrolled
const cfuns = (sin, cos)
@unroll function test_loop(n::Int64, cfuns::Tuple)
    t = 0.0
    for i = 1:n
        @unroll for j in 1:length(cfuns)
            t += cfuns[j](i)
        end
    end
    return t
end
@time test_loop(10^6, cfuns) # 20.1k allocations
@time test_loop(10^6, cfuns) # 6 allocations