JuliaCon 2023

When type instability matters
07-28, 16:10–16:20 (US/Eastern), 32-144

Type instabilities are not always bad! Using non-concrete types, and avoiding method specialization and type inference can help with improving latency and, in specific cases, runtime performance. The latter is observed in inherently dynamic contexts with no way to compile all possible method signatures upfront, because code needs to be compiled at points of dynamic dispatch by design. We present a concrete case we face in our production environment, additional examples, and related trade-offs.


Writing type-stable code has largely been accepted as a standard good practice. When the compiler can fully infer the types which flow through a program, it can apply optimizations and specialize to emit fast code for the specific function signatures that get compiled.
The process of method specialization and type inference is expensive and a main source of the perceived latency when using Julia. While in most cases, this one-time cost is acceptable for the performance gains at runtime, there are specific contexts in which the cost of such analyses becomes prohibitive.
In this talk, we present situations which may benefit from preventing the compiler to reason too much about the code, considering the trade-off between compilation and execution time. Such situations include evaluating generated code, especially generating new types. We also discuss other cases, in which certain data structures benefit from having non-concrete fields, such as Expr and other tree-shaped data structures.

Bayesian researcher and Julia developer for quite some time now. I am part of the Julia Gaussian Process team and developed all kind of serious tools for statistical analysis and more stupid stuff like WatchJuliaBurn.jl or DeepFry.jl

Cédric Belmant is an applied mathematician and programmer, with a strong interest in 3D graphics, geometry processing and application development. He believes the expressive power of the Julia programming language is key to building applications and tools with minimal complexity, and has been exploring ways to integrate computer graphics in the Julia ecosystem.

This speaker also appears in: