# List of elements with unknown type, is it bad?

**URL:** <https://discourse.julialang.org/t/list-of-elements-with-unknown-type-is-it-bad/53893>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 25, 2021, 9:44am UTC](https://discourse.julialang.org/t/list-of-elements-with-unknown-type-is-it-bad/53893 "2021-01-25T09:44:18Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 25, 2021, 1:14pm UTC](https://discourse.julialang.org/t/list-of-elements-with-unknown-type-is-it-bad/53893/4 "2021-01-25T13:14:42Z")

</div>

Where you will have performance problems is if later you want evaluate functions which take those elements of the array as parameters, and the functions will have to be dynamically dispatched at run time for every element of the array. The best alternative is to try to reorganize the data to avoid mixed-type arrays, but detailed discussions on that can be found in these threads:

> [@Disabling allocations](https://discourse.julialang.org/t/disabling-allocations/51028):
>
> Is there a way of disabling allocations altogether within the body of a function? I optimized my code to avoid all allocations, but they keep creeping back in with changes and are annoying to locate. I would much rather have a compile-time error.

> [@Performance drawback with subtyping](https://discourse.julialang.org/t/performance-drawback-with-subtyping/51939/14):
>
> I agree with you @lmiq, we should study a more realistic case. So I apply the sin function as you did and changed n = 100,000,000. Because with a little n there is a big influencial of processes at operation system. My results was: with dynamic dispatch: 1.120 s (0 allocations: 0 bytes) with splitting: 1.121 s (0 allocations: 0 bytes) with functors: 1.144 s (0 allocations: 0 bytes) with cast: 1.159 s (0 allocations: 0 bytes) simple sum of an array of Float64 of same size: 504.909 ms…

> [@Macro to write function with many conditionals](https://discourse.julialang.org/t/macro-to-write-function-with-many-conditionals/51616/8):
>
> It is even more simple then that. If all types are subtypes of some abstract class, then you can use subtypes function to generate list of all subtypes. It’s little more involved in case of parametric case, so I am not sure whether it is possible to write generic macro that can solve them all, but if you know you hierarchy beforehand you bend it appropriately. As an example for non parametric types, here is an adaptation of the ManualDispatch.jl function function \_unionsplit(type, x, call) …

(look particularly at Skoffer’s answers and the macro he provides in the third thread).

---

_[View the full topic](https://discourse.julialang.org/t/list-of-elements-with-unknown-type-is-it-bad/53893)._
