# Static Compilation in Julia

**URL:** <https://discourse.julialang.org/t/static-compilation-in-julia/124416>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 3, 2025, 5:35pm UTC](https://discourse.julialang.org/t/static-compilation-in-julia/124416 "2025-01-03T17:35:44Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [January 3, 2025, 8:43pm UTC](https://discourse.julialang.org/t/static-compilation-in-julia/124416/8 "2025-01-03T20:43:49Z")

</div>

Here’s an example of static compilation, adapted from the [instructions here](https://jbytecode.github.io/juliac/). A small program requiring GC compiles to 18 MB on my Linux machine (libc x86\_64).

First, I install the Julia nightly channel:

```
#> juliaup add nightly

```

Then I cloned the Julia git repo to get the juliac scripts:

```
#> git clone https://github.com/JuliaLang/julia.git

```

Here’s a small program `try.jl` which stores the squares of the numbers 1, 2, … ,100 into a dictionary (GC is needed for this data structure). Then it prints out the value for the key 10.

```julia
module Try

Base.@ccallable function main()::Cint
    square_dict = Dict(i => i^2 for i in 1:100)
    println(Core.stdout, square_dict[10])
    return 0
end

end # End of module Try

```

I compile the program with

```
#> julia +nightly julia/contrib/juliac.jl --output-exe try --experimental --trim try.jl

```

This took about 22 seconds and produced the binary `try` with a size 18 MB. Executing the produced binary took about 37 milliseconds.

```
#> time ./try
100

real	0m0.037s
user	0m0.014s
sys 0m0.027s

```

P.S. since this is experimental stuff, it goes without saying that the information could become outdated very quickly.

---

_[View the full topic](https://discourse.julialang.org/t/static-compilation-in-julia/124416)._
