# Code compiles each time it triggered

**URL:** https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839
**Category:** Performance
**Tags:** docker, package-compiler, sysimage
**Created:** [March 10, 2023, 4:18am UTC](https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839 "2023-03-10T04:18:10Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Sandy45](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sandy45](https://discourse.julialang.org/u/Sandy45)
#### Post date: [March 10, 2023, 4:18am UTC](https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839/1 "2023-03-10T04:18:11Z")

</div>

I’ve deployed my Julia code to AWS using Docker containers with enabling multiple threads, The issue we are facing is whenever HTTP end point (Julia) has been triggered process is compiling every time since because of using multiple processes whatever available process is getting triggered.

I am working on approach to pre-compile the code using packagecompiler and create binary file using sysimage. I would like to check if this is the appropriate solution or can someone please shade some lights on this?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [March 10, 2023, 4:24am UTC](https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839/2 "2023-03-10T04:24:38Z")

</div>

Yeah. PackageCompiler is exactly the right solution here.

---

<div class="post-metadata">

### Author: ![Sandy45](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sandy45](https://discourse.julialang.org/u/Sandy45)
#### Post date: [March 10, 2023, 4:59am UTC](https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839/3 "2023-03-10T04:59:09Z")

</div>

@Oscar_Smith Thanks for prompt response, can you please let me know if i need to use precompile\_execution\_file keyword or precompile\_execution\_statement while compiling with sysimage? My docker entry point is julia - - project http\_calc.jl, so is it okay if i compiled sysimage with all precompiled statements and list my sysimage.so as entry point?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [March 10, 2023, 5:06am UTC](https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839/4 "2023-03-10T05:06:41Z")

</div>

Running a representative workload will make the sysimage better, although how much better is very application specific.

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [March 10, 2023, 8:19am UTC](https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839/5 "2023-03-10T08:19:04Z")

</div>

> [@Sandy45](#):
>
> can you please let me know if i need to use precompile\_execution\_file keyword or precompile\_execution\_statement while compiling with sysimage?

In my experience, `precompile_execution_file` is very useful if you can create a script that contains a representative workload and can run entirely non-interactively. In the case of an HTTP server, that could involve having minimalistic client code running in a separate asynchronous task in order to trigger the relevant endpoints in the server.

If having a non-interactive script becomes in some way too much work, it might be easier to create a `precompile_statements_file` in an interactive way ahead of `PackageCompiler`-time.

This would involve running your project like so:

```julia
julia --project --trace-compile=precompile_statements.jl http_calc.jl

```

and then using it for a bit interactively in order to exercise as many features as possible. You can feed `PackageCompiler` with the generated `precompile_statements.jl` file in order to have a larger fraction of you code baked in the system image. An example use of this technique is detailed in the [`PackageCompiler` tutorial about `OhMyREPL`](https://julialang.github.io/PackageCompiler.jl/dev/examples/ohmyrepl.html#manual-omr)

> [@Sandy45](#):
>
> My docker entry point is julia - - project http\_calc.jl, so is it okay if i compiled sysimage with all precompiled statements and list my sysimage.so as entry point?

Yes, your new entry point would look like

```julia
julia --project --sysimage http_calc_sysimage.so http_calc.jl

```

---

<div class="post-metadata">

### Author: ![Sandy45](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sandy45](https://discourse.julialang.org/u/Sandy45)
#### Post date: [March 10, 2023, 5:52pm UTC](https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839/6 "2023-03-10T17:52:09Z")

</div>

@ffevotte Thanks for your help! Yes, I am able to compile using precompile\_statements\_file and see huge difference in compilation time.

---

<div class="post-metadata">

### Author: ![Sandy45](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sandy45](https://discourse.julialang.org/u/Sandy45)
#### Post date: [March 10, 2023, 6:08pm UTC](https://discourse.julialang.org/t/code-compiles-each-time-it-triggered/95839/7 "2023-03-10T18:08:37Z")

</div>

One issue i noticed was if any new function/package added to the code should we need to do same steps? Since currently it seems like pre\_compile\_statement file will be overwritten if we start compile trace again. Do we have any flag for not to overwrite it?
