# 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:** 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:** [May 26, 2021, 11:45pm UTC](https://discourse.julialang.org/t/avoiding-vectors-of-abstract-types/61883/4 "2021-05-26T23:45:56Z")

</div>

> [@RobertGregg](#):
>
> Each field is a vector of the same concrete subtypes, but each instance is given an index

If that is possible this is by far the best approach, I think.

I don’t know if you already followed this thread, a lot has been discussed there, and that links to other related topics (one the things tried is that approach, which is the faster of all for the toy examples there). This last thread introduces new perspectives as well:

> [@Union splitting vs C++](https://discourse.julialang.org/t/union-splitting-vs-c/61772/1):
>
> This is a continuation from this thread: [Performance drawback with subtyping - #31 by paulmelis](https://discourse.julialang.org/t/performance-drawback-with-subtyping/51939/31) Here we have two codes, which compute someting simple (the sum of the values of a field of a type in an array of mixed types of objects). Typical case where it is hard to be type-stable and avoid run-time dispatch. With 2 different types in the list of types, union splitting kicks in in Julia and the code is fast. With more (in the present example 5 types), it does not. In the C++ code clearly it do…

---

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