A formal definition of type stability and its impact on JIT compilation in the Julia language, with an analysis of the prevalence of type-stable code in popular Julia packages. Type stability of methods is important for performance of Julia programs, because it enables several key compiler optimizations such as specialization and devirtualization of dynamically dispatched method calls.
The formal definition is given with respect to Jules, a miniature language
with multiple dynamic dispatch and an optimizing JIT compiler which performs
type-based method specialization and devirtualization.
-
OOPSLA 2021
Type Stability in Julia: Avoiding Performance Pathologies in JIT CompilationAuthors: Artem Pelenitsyn, Julia Belyakova, Benjamin Chung, Ross Tate, Jan Vitek
DOI: 10.1145/3485527
Venue: Proc. ACM Program. Lang., Volume 5, OOPSLA, Article 150 (26 pages)
Reviews
As a scientific programming language, Julia strives for performance but also provides high-level productivity features. To avoid performance pathologies, Julia users are expected to adhere to a coding discipline that enables so-called type stability. Informally, a function is type stable if the type of the output depends only on the types of the inputs, not their values. This paper provides a formal definition of type stability as well as a stronger property of type groundedness, shows that groundedness enables compiler optimizations, and proves the compiler correct. We also perform a corpus analysis to uncover how these type-related properties manifest in practice.