Array Type and Values-as-Parameters Performance penalty?

The user manual at Performance Tips · The Julia Language suggests that we avoid types with values as parameters. However, doesn’t the base Array{T, N} have a value-parameter N? How can Base get away with this but have good performance?

My thoughts were that it’s either

Also, I had a hard time tracking down the C source for the Array{T, N} type. Looked in src/array.c, but didn’t find anything obvious to myself, an outsider to Julia source. Would be interested if someone can provide a pointer to understand where this type is defined.

Thank you!

1 Like

There is no runtime penalty for types with values as parameters. Just the opposite: it can sometimes allow you to write extremely efficient code (see StaticArrays.jl for example). The danger is that by putting values into your type parameters, you force Julia to compile new code for every different value in your program (since each value creates a different type). That means more time spent compiling and potentially more time and space spent on code generation and loading.

6 Likes

Ah, thank you! I actually meant to ask about compile-time performance rather than runtime performance. My coworkers and I are trying to understand the factors that lead to slow compile-times. Still, I think you answered my question. As long as there is a small number of unique values that will be used as the value-parameter, compile-performance should not suffer.

2 Likes