# Avoid slowness in the first execution of a function

**URL:** <https://discourse.julialang.org/t/avoid-slowness-in-the-first-execution-of-a-function/66509>\
**Category:** New to Julia\
**Tags:** question, performance\
**Created:** [August 16, 2021, 7:48pm UTC](https://discourse.julialang.org/t/avoid-slowness-in-the-first-execution-of-a-function/66509 "2021-08-16T19:48:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frisus95](https://avatars.discourse-cdn.com/v4/letter/f/77aa72/32.png) [@Frisus95](https://discourse.julialang.org/u/Frisus95)\
**Post date:** [August 16, 2021, 7:48pm UTC](https://discourse.julialang.org/t/avoid-slowness-in-the-first-execution-of-a-function/66509/1 "2021-08-16T19:48:43Z")

</div>

Hello everyone.

I noticed that the first time I run a function with julia, the execution time (as well as the allocated memory) is significantly higher than subsequent executions, at least in my code.

Since I have to run my code on a cluster remotely (i.e. the code in julia starts and runs only once) is there any trick to avoid making execution faster from the start?

Thanks, good day everyone.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 16, 2021, 7:49pm UTC](https://discourse.julialang.org/t/avoid-slowness-in-the-first-execution-of-a-function/66509/2 "2021-08-16T19:49:47Z")

</div>

not really, this is just how Julia works, JIT

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [August 16, 2021, 8:00pm UTC](https://discourse.julialang.org/t/avoid-slowness-in-the-first-execution-of-a-function/66509/3 "2021-08-16T20:00:21Z")

</div>

The longer time is due to precompilation. If your code uses packages that need precompilation maybe a custom sys image might help. Of course that needs to be compiled too so only worth it if you have similar workloads multiple times.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [August 16, 2021, 8:14pm UTC](https://discourse.julialang.org/t/avoid-slowness-in-the-first-execution-of-a-function/66509/4 "2021-08-16T20:14:00Z")

</div>

> **[GitHub - dmolina/DaemonMode.jl: Client-Daemon workflow to run faster scripts...](https://github.com/dmolina/DaemonMode.jl)**
>
> Client-Daemon workflow to run faster scripts in Julia - GitHub - dmolina/DaemonMode.jl: Client-Daemon workflow to run faster scripts in Julia

or

> **[GitHub - JuliaLang/PackageCompiler.jl: Compile your Julia Package](https://github.com/JuliaLang/PackageCompiler.jl)**
>
> Compile your Julia Package. Contribute to JuliaLang/PackageCompiler.jl development by creating an account on GitHub.

are the current solutions/workarounds depending on your needs and what you are allowed on the cluster.
