# Alternate ways to deal with arrays of subtypes of abstract type

**URL:** https://discourse.julialang.org/t/alternate-ways-to-deal-with-arrays-of-subtypes-of-abstract-type/79689
**Category:** Performance
**Tags:** type, type-stability
**Created:** [April 19, 2022, 1:03pm UTC](https://discourse.julialang.org/t/alternate-ways-to-deal-with-arrays-of-subtypes-of-abstract-type/79689 "2022-04-19T13:03:53Z")
**Posts on this page:** 1
**Showing post:** 12

<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: [April 19, 2022, 4:15pm UTC](https://discourse.julialang.org/t/alternate-ways-to-deal-with-arrays-of-subtypes-of-abstract-type/79689/12 "2022-04-19T16:15:20Z")

</div>

Just for reference, this kind of thing was discussed in other threads:

> [@Performance drawback with subtyping](https://discourse.julialang.org/t/performance-drawback-with-subtyping/51939):
>
> Hello, I’ve a problem with subtype, see the code: abstract type LineAbstract end mutable struct LineA \<: LineAbstract color::String end mutable struct LineB \<: LineAbstract length::Int end mutable struct Picture lines::Vector{LineAbstract} end I’m putting here a conceptual problem of my real problem because it’s more easy to understand. The class Picture have lines, and they share some attributes in common, but the have it’s own. In class Picture I have all kinds of l…

> [@Union splitting vs C++](https://discourse.julialang.org/t/union-splitting-vs-c/61772):
>
> 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/alternate-ways-to-deal-with-arrays-of-subtypes-of-abstract-type/79689)._
