Creating a performant function using metaprogramming

Take a look at this thread: Efficient recursive tuple construction

it is the same problem. At some point you just have to use standard arrays.