Why type instability?

I like that example. As you say, performance isn’t inherent – it’s a moving target depending on what optimizations a compiler happens to have. Another good example of where type instability can be useful is untagged unions. We use this for the match function: nothing indicates no match whereas a match object indicates a match. Part of the chaos in the data ecosystem stems from trying what amounts to a tagged union Nullable, which must be explicitly wrapped and unwrapped; this pattern turns out to be quite awkward and inconvenient to use, however. Work by Jacob Quinn and Jameson Nash towards making an utagged union approach (see Nulls.jl) with good performance, which will be much more convenient to use. This would be impossible with enforced type stability.

3 Likes