# Array Type and Values-as-Parameters Performance penalty?

**URL:** <https://discourse.julialang.org/t/array-type-and-values-as-parameters-performance-penalty/24092>\
**Category:** Performance\
**Created:** [May 10, 2019, 9:13pm UTC](https://discourse.julialang.org/t/array-type-and-values-as-parameters-performance-penalty/24092 "2019-05-10T21:13:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [May 10, 2019, 9:13pm UTC](https://discourse.julialang.org/t/array-type-and-values-as-parameters-performance-penalty/24092/1 "2019-05-10T21:13:46Z")

</div>

The user manual at [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/performance-tips/index.html#The-dangers-of-abusing-multiple-dispatch-(aka,-more-on-types-with-values-as-parameters)-1) 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

- `N` is an Int, which is an isbits type?
- or because the `Array` struct is defined in C (according to [https://github.com/JuliaLang/julia/blob/master/base/boot.jl](https://github.com/JuliaLang/julia/blob/master/base/boot.jl)), which means it can defy performance guidelines?

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!

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 10, 2019, 10:00pm UTC](https://discourse.julialang.org/t/array-type-and-values-as-parameters-performance-penalty/24092/2 "2019-05-10T22:00:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [May 13, 2019, 12:39pm UTC](https://discourse.julialang.org/t/array-type-and-values-as-parameters-performance-penalty/24092/3 "2019-05-13T12:39:52Z")

</div>

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.
