Why StaticArrays are not recommended for large Arrays?

There is a warning that one should not use StaticArray for very large arrays:

Note that in the current implementation, working with large StaticArray s puts a lot of stress on the compiler, and becomes slower than Base.Array as the size increases. A very rough rule of thumb is that you should consider using a normal Array for arrays larger than 100 elements.

Why so? What is the intrinsic limitation that hurts the performance of large StaticArray?

AFAIK there are two reasons:

  1. each dimension & type combination is its own type, which entails a compilation cost

  2. loops start to dominate unrolled calculations

For actual code, it is always best to just benchmark.

1 Like

A NTuple{N, T} is treated the same as Tuple{T, T, T, T, T, ...}. Type computations then become very expensive as N becomes large. WIP: Give NTuple{N, T} a layout by Keno · Pull Request #31681 · JuliaLang/julia · GitHub is some WIP to handle that (AFAIU).