If Runtime isn't Funtime: Controlling Compile-time Execution
07-25, 14:30–15:00 (US/Eastern), Elm A

"This block will compile away," the comments say. But will it? In this talk we'll see some scenarios where controlling compile-time vs runtime execution is crucial for performance, and we'll discuss some ideas that might make this control easier in Julia.


Julia's ability to compile away complex logic is remarkable. Especially in recent releases, Const-propagation is a thing to behold! But we've found it can be hard to reason about why some operations are compiled away (or why they aren't), and even harder to control that behavior. What's more, that behavior can change as your code evolves, or Julia is updated, and it's difficult to test.

In Julia, the distinction between compile-time and runtime is deliberately muddy: compilation itself happens during runtime; a function may be compiled once, many times or never—it might even be compiled more times than it runs. Still, there are cases where we expect a function to be compiled once, early on, and then need it to run extremely quickly, many times, in a tight loop, where controlling the ability to move work from runtime to compile-time is critical.

This talk will explore a few such motivating cases we've seen at RelationalAI, including in pieces of the FixedPointDecimals.jl library. We'll examine the options currently available in Julia for controlling compile-time execution, and their pros and cons, including some lessons-learned about the pain we've experienced with @generated. We'll study the approach modern C++ is taking to this problem, with its constexpr annotation. And we'll propose a few ideas for how we might add features to Julia that could increase our control over this fierce compiler.

Nathan Daly is a Software Engineer at RelationalAI. He was first introduced to the idea of contributing to JuliaLang as one small way to help fight climate change by making scientific computing a little bit easier: http://worrydream.com/ClimateChange

This speaker also appears in: