Constant propagation
One very useful optimization that the Julia compiler implements when calling functions is called constant propagation. When a function is called with an argument that is known at compile time, the invocation can happen once at compile time, and the call is then replaced with a constant value at runtime. While we have seen some constant values being combined within a single function (with inlining), constant propagation occurs across a function call boundary – which means that this is a more complex, and powerful, optimization.
As a simple example to demonstrate constant propagation, we define a sqr function that takes one argument and then returns the square of that value. A second function, sqr2, calls the first function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access