# Efficiency of abstract types vs \`Any\`

**URL:** https://discourse.julialang.org/t/efficiency-of-abstract-types-vs-any/129518
**Category:** General Usage
**Tags:** question
**Created:** [June 1, 2025, 8:50am UTC](https://discourse.julialang.org/t/efficiency-of-abstract-types-vs-any/129518 "2025-06-01T08:50:15Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [June 2, 2025, 2:07pm UTC](https://discourse.julialang.org/t/efficiency-of-abstract-types-vs-any/129518/11 "2025-06-02T14:07:35Z")

</div>

> [@MilesCranmer](#):
>
> Correct me if im wrong, but it might even be slower sometimes, because the runtime has to do an extra type assertion at parts of the code.

there has been quite a few related discussion on union splitting / world age splitting in relation to performence, you might be interested in them:

> [@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…

> [@Dramatic performance change by adding additional unused method](https://discourse.julialang.org/t/dramatic-performance-change-by-adding-additional-unused-method/71771/22):
>
> I tried with having a Vector of abstract types. Like this: abstract type AbstractPlacement{T\<:AbstractFloat} end #---Volume------------------------------------------------------------------------- struct Volume{T\<:AbstractFloat, S\<:AbstractShape{T}, M\<:AbstractMaterial} label::String shape::S # Reference to the actual shape material::M # Reference to material daughters::Vector{AbstractPlacement{T}} end #---PlacedVolume--------…

---

_[View the full topic](https://discourse.julialang.org/t/efficiency-of-abstract-types-vs-any/129518)._
