ELI5: why is it not possible yet to create standalone binaries using Julia?

Hi!

My knowledge about compilers is very limited. I am wondering: since Julia creates machine code using LLVM, why I cannot compile standalone software? If I use PackageCompiler, for example, I can create a binary, but it is linked against libjulia, which is huge. Is it some current limitation or something impossible to accomplish?

1 Like

The basic problem is that by default, Julia is just ahead of time compiled. This is because each combination of types for a function requires a new bytecode to be compiled. The problem with “just compiling everything” if taken literally, would mean compiling every function with every combination of types possible. For example, if I define f(a,b,c,d,e)=a, although this it’s a very simple function, Julia would have to generate millions of function definitions. As such, the problem you really want to solve is “compile all my functions for all type combinations my program might want to use”. This is what packagecompilerx does, but it requires a good test suite, as that is what it uses to build the list of things to compile.

5 Likes

So, in theory, it would be possible to do that if I fix all the argument types using annotations like ::Int64, right?

No (and even if it did, you still shouldn’t). Even if this were the case, in-lining and multiple dispatch mean that you could easily want to generate many different versions of the same executable. The reason you shouldn’t want to even if you could is that doing so would remove the composability and extensibility that make Julia such a powerful language. The better solution is to have a good test-suite that exercises your full program, and to use PackageCompilerX.

3 Likes

I see, the only problem is that if I want to build a simple text user interface and create an executable, it would likely be larger than 150 MiB because of the required libraries.

1 Like

Yeah, this is a known problem, and a lot of work is being put into solving it. It wouldn’t surprise me if by 1.5 or 1.6 we have a solution involving static analysis to figure out what libraries your code might call, and removing the useless ones.

4 Likes

Nice! Thanks for the help :slight_smile:

Can you point me to some PRs?