# Avoiding Vectors of Abstract Types

**URL:** <https://discourse.julialang.org/t/avoiding-vectors-of-abstract-types/61883>\
**Category:** Performance\
**Tags:** question, type-stability\
**Created:** [May 26, 2021, 7:20pm UTC](https://discourse.julialang.org/t/avoiding-vectors-of-abstract-types/61883 "2021-05-26T19:20:06Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [January 27, 2022, 4:57pm UTC](https://discourse.julialang.org/t/avoiding-vectors-of-abstract-types/61883/9 "2022-01-27T16:57:57Z")

</div>

> [@filchristou](#):
>
> In this case I am wondering: Would it hurt to just use `Union` of all subtypes ? I mean is there a point where, when `Union` type gets too long it starts hurting efficiency ?

If I remember correctly, the small union optimization that makes `Vector{Union{...}}` efficient has a limit of `typemax(UInt8)` types in the union, but [performance will degrade due to other compiler factors when going above 3-4 types](https://discourse.julialang.org/t/performance-tips-for-union-types/13928/5). Unless this has changed since 2018 which it very well might have.

---

_[View the full topic](https://discourse.julialang.org/t/avoiding-vectors-of-abstract-types/61883)._
