Performance drawback with subtyping

If you only need a few types, you probably want something like

struct Picture
   lines :: Vector{Union{LineA,LineB}}
end

still that can come with performance problems, because if you define a method that acts on these types, and you dispatch on this vector at run time, the dynamic dispatch will have a performance penalty. If you have many types, probably you will need some of the ideas that were dicussed in these threads, because at the end they ended up in a discussion of exactly that problem:

A related follow up is here:

(and I wrote a simple example here, but I have yet to write it in detail: https://m3g.github.io/JuliaCookBook.jl/stable/splitting/

2 Likes