Performance tips for Union Types

Yes it works with more than two types, but there’s various limits in various parts of the compiler that’ll kick in if you go much beyond that (limits to the number of union elements, number of applicable methods considered, maximum union splitting branching factor, etc.). As a rule of thumb, I’d say around 3 or 4 union elements will probably always stay under all these limits, but it depends on the specific case and which part you care about (e.g. the storage optimization is effective up to 255 elements I believe).

5 Likes