Inference
You can start a Julia session, edit (for example to insert print
statements), and then replace Core.Compiler
in your running session by navigating to base
and executing include("compiler/compiler.jl")
. This trick typically leads to much faster development than if you rebuild Julia for each change.
Alternatively, you can use the package to track the compiler changes by using the command Revise.track(Core.Compiler)
at the beginning of your Julia session. As explained in the Revise documentation, the modifications to the compiler will be reflected when the modified files are saved.
If your debugging adventures require a MethodInstance
, you can look it up by calling Core.Compiler.specialize_method
using many of the variables above. A CodeInfo
object may be obtained with
Much of the hardest work for inlining runs in ssa_inlining_pass!
. However, if your question is “why didn’t my function inline?” then you will most likely be interested in inline_worthy
, which makes a decision to inline the function call or not.
The foundation of the cost-model is a lookup table, implemented in add_tfunc
and its callers, that assigns an estimated cost (measured in CPU cycles) to each of Julia’s intrinsic functions. These costs are based on standard ranges for common architectures (see for more detail).
We supplement this low-level lookup table with a number of special cases. For example, an :invoke
expression (a call for which all input and output types were inferred in advance) is assigned a fixed cost (currently 20 cycles). In contrast, a :call
expression, for functions other than intrinsics/builtins, indicates that the call will require dynamic dispatch, in which case we assign a cost set by Params.inline_nonleaf_penalty
(currently set at 1000
). Note that this is not a “first-principles” estimate of the raw cost of dynamic dispatch, but a mere heuristic indicating that dynamic dispatch is extremely expensive.
The line costs are in the left column. This includes the consequences of inlining and other forms of optimization.