Understanding better JIT and LLVM in Julia

The biggest reason julia is JIT compiled is that for a basic function like f(a,b)=a+b, there are probably tens of thousands of possible things this could compile to depending on what types a and b are. This gets exponentially harder for functions with more arguments. Thus Julia’s approach is to only f for the types with which it is actually called. For a simple program whose compiled output can not fit on your computer cosider

x = tuple([rand()>.5 ? 1 : 2.0 for _=1:200]...)
f(x) = sum(x)
f(x)

There are 2^200 possible functions to compile here. Good luck fitting that on a hard drive.

Furthermore, even if all of your code has static types for everything, Julia itself has lots of code (eg +) that don’t specify concrete types for everything. Thus your code being all statically typed is mostly irrelevant.

p.s. in this case, a very smart compiler could probably make a fallback that checks element types and does the right type of addition, but solving this generally would basically require including a Julia interpreter (or JIT) in the compiled binary.

8 Likes