# Why is static compilation difficult

**URL:** <https://discourse.julialang.org/t/why-is-static-compilation-difficult/103796>\
**Category:** General Usage\
**Created:** [September 12, 2023, 7:46pm UTC](https://discourse.julialang.org/t/why-is-static-compilation-difficult/103796 "2023-09-12T19:46:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 12, 2023, 9:30pm UTC](https://discourse.julialang.org/t/why-is-static-compilation-difficult/103796/3 "2023-09-12T21:30:11Z")

</div>

> [@Could Someone Explain To Me the Desire for Small Julia Binaries?](https://discourse.julialang.org/t/could-someone-explain-to-me-the-desire-for-small-julia-binaries/96484):
>
> Hi folks, I’ve seen this notion pop-up repeatedly about wanting small binaries created within the Julia ecosystem. I personally have been quite confused about this desire due to probably not working in a space where having small binaries is desired. My mental oversimplification of this problem is that as personal computer storage space has gotten so large, having big binaries is not a problem any more – as I see it. But I must be missing something crucial. Could anyone explain to me why we wa…

Is a good thread for some previous discussion.

> [@cstjean](#):
>
> Did I miss anything from the runtime?

The big parts you’ve missed are “task management” and “exception handling”, as well as I/O. All of these are handled by the runtime as well, and without that, there’s no threading, there’s no printing (sort of), there’s no REPL, there’s no strings/arrays (due to allocations).

The truth of the matter is - the runtime does SO MUCH work for you in the background and enables so many different things that running without one is basically only possible in extremely limited circumstances. One such examples are the prototypical usecases in StaticCompiler, another is microcontrollers (where I am currently working on getting a tiny minimal “runtime”, consisting of nothing more than an allocator, to at least be able to have some global variables and an array). The reason there’s basically no middle ground is because the various features the runtime provides are all depending on each other - you need allocations for everything, in some form or another, to be able to even build a string you’d use in an error message. You need strings and arrays to be able to spawn a new task,and you need to be able to throw exceptions in case the task couldn’t be spawned.

And this doesn’t even get into what you need for dynamic dispatch! In general, that requires the compiler in its full capacity (though you could compile only a subset and fatally crash if you’d have to compile something new).

So in the end, either you’re programming in a very restrictive environment already (embedded) and can afford to implement things “just right”, or you’re going to need large parts of a runtime, in order to be able to use existing libraries more or less as-is in your static binary.

I’d love to also link my talk from JuliaCon about compiling some Julia code to an Arduino (which covers some of the hard parts of the extreme embedded side), but it seems something has gone wrong in the video processing pipeline and it’s not yet uploaded as a standalone video. If you want to look for it, it’s in the recording of the second day of 26-100, somewhere around the 5:30 mark if I’m not mistaken. I’ll edit the video in here once it’s standalone.

EDIT: It’s uploaded now!

[![](https://global.discourse-cdn.com/julialang/original/3X/7/1/71e0cb5f6706601fdd2b0f1bd648d91294add096.jpeg "Running Julia Code Baremetal on an Arduino | Valentin Bogad | JuliaCon 2023") ](https://www.youtube.com/watch?v=GKKpB07GHmU)

* * *

The general TL;DR though is “this is just really big and complicated work, that runs into assumptions that were made in the past and edge cases of the current pipeline that are not easy to solve”.

---

_[View the full topic](https://discourse.julialang.org/t/why-is-static-compilation-difficult/103796)._
