# Type stability issues when using StaticArrays

**URL:** <https://discourse.julialang.org/t/type-stability-issues-when-using-staticarrays/19126>\
**Category:** Performance\
**Tags:** type-stability, staticarrays\
**Created:** [December 30, 2018, 7:32pm UTC](https://discourse.julialang.org/t/type-stability-issues-when-using-staticarrays/19126 "2018-12-30T19:32:20Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![aortizb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aortizb/32/6513_2.png) [@aortizb](https://discourse.julialang.org/u/aortizb)\
**Post date:** [January 3, 2019, 1:48pm UTC](https://discourse.julialang.org/t/type-stability-issues-when-using-staticarrays/19126/22 "2019-01-03T13:48:25Z")

</div>

@rdeits My complete code reads the value for “nelementnodes” from an input text file. The input text file can have a different value for nelementnodes from run to run. Will this approach (value type argument) still work as intended?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 3, 2019, 2:47pm UTC](https://discourse.julialang.org/t/type-stability-issues-when-using-staticarrays/19126/23 "2019-01-03T14:47:34Z")

</div>

See [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/performance-tips/index.html#kernel-functions-1).

As long as you create your types outside the function that do the core computation, you are fine.

---

<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:** [January 3, 2019, 2:49pm UTC](https://discourse.julialang.org/t/type-stability-issues-when-using-staticarrays/19126/24 "2019-01-03T14:49:15Z")

</div>

Sure! As long as your code looks something like:

```julia
function main(filename)
  nelementnodes = read_data_from_file(filename)
  long_running_computation(Val(nelementnodes))
end

```

then you should be fine. There’s a computational cost to constructing a `Val` from a run-time value, but that cost is only a few hundred _nanoseconds_ and you’re only paying it once per call of `long_running_computation`, so that should be completely negligible.

---

<div class="post-metadata">

**Author:** ![aortizb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aortizb/32/6513_2.png) [@aortizb](https://discourse.julialang.org/u/aortizb)\
**Post date:** [January 3, 2019, 3:35pm UTC](https://discourse.julialang.org/t/type-stability-issues-when-using-staticarrays/19126/25 "2019-01-03T15:35:38Z")

</div>

Thank you @kristoffer.carlsson !

---

<div class="post-metadata">

**Author:** ![aortizb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aortizb/32/6513_2.png) [@aortizb](https://discourse.julialang.org/u/aortizb)\
**Post date:** [January 3, 2019, 3:36pm UTC](https://discourse.julialang.org/t/type-stability-issues-when-using-staticarrays/19126/26 "2019-01-03T15:36:34Z")

</div>

Thank you @rdeits !

[Previous page](https://discourse.julialang.org/t/type-stability-issues-when-using-staticarrays/19126.md?page=1)
