# How can I speed up script overhead time?

**URL:** <https://discourse.julialang.org/t/how-can-i-speed-up-script-overhead-time/67676>\
**Category:** New to Julia\
**Tags:** compilation, aot, jit\
**Created:** [September 4, 2021, 3:55am UTC](https://discourse.julialang.org/t/how-can-i-speed-up-script-overhead-time/67676 "2021-09-04T03:55:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![solaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/solaris/32/28875_2.png) [@solaris](https://discourse.julialang.org/u/solaris)\
**Post date:** [September 4, 2021, 3:55am UTC](https://discourse.julialang.org/t/how-can-i-speed-up-script-overhead-time/67676/1 "2021-09-04T03:55:21Z")

</div>

It seems like there’s overhead running Julia scripts that seem unreasonable and maybe I’m doing something wrong or missing a step.

For example, I ran the nbody benchmark on my machine and gave it a few numbers. nbody basically does a bunch of math and nothing else (no plotting or graphics). It just prints 3 numbers at the end. Here are the results (higher numbers mean more iterations/complexity):

nbody 5000000 took 0.52 seconds which is amazing!  
nbody 50000 took 0.31  
nbody 5 took 0.29  
nbody 1 took 0.28

[Link to code](https://github.com/hanabi1224/Programming-Language-Benchmarks/blob/main/bench/algorithm/nbody/7.jl)

So whether doing a 50k object simulation or only doing 1 takes about the same time which means there’s some overhead in running a script. Why is there overhead? Is julia loading a bunch of packages when we call scripts? Is there any other way to reduce the overhead?

I’m running the script in a command prompt in windows 10.

EDIT: The culprit in this case was @printf. Why the heck is print so slow?!

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 4, 2021, 4:45am UTC](https://discourse.julialang.org/t/how-can-i-speed-up-script-overhead-time/67676/2 "2021-09-04T04:45:49Z")

</div>

The overhead is the JIT compile time.

The question is, how to you plan to use Julia?

For interactive use use the REPL and the package Revise.  
[Home · Revise.jl](https://timholy.github.io/Revise.jl/stable/) If you really need to run a script again and again use [https://github.com/dmolina/DaemonMode.jl](https://github.com/dmolina/DaemonMode.jl) .

---

<div class="post-metadata">

**Author:** ![solaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/solaris/32/28875_2.png) [@solaris](https://discourse.julialang.org/u/solaris)\
**Post date:** [September 4, 2021, 5:15am UTC](https://discourse.julialang.org/t/how-can-i-speed-up-script-overhead-time/67676/3 "2021-09-04T05:15:26Z")

</div>

I’m looking to use it in real-time applications. Gaming related so performance and low-latency is important. Julia scripts would be run embedded in a C++ application.  
The Revise package did help a lot. A big chunk of the problem with performance is simply using @printf which is strange to me.  
The daemon mode is interesting too. Is there a way to do aot compiling or not re-compile if a script hasn’t changed?

---

<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:** [September 4, 2021, 5:16am UTC](https://discourse.julialang.org/t/how-can-i-speed-up-script-overhead-time/67676/4 "2021-09-04T05:16:56Z")

</div>

Currently there is no way to aot compile (PackageCompiler is close-ish).

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 4, 2021, 2:34pm UTC](https://discourse.julialang.org/t/how-can-i-speed-up-script-overhead-time/67676/5 "2021-09-04T14:34:48Z")

</div>

Is RPC an option for you? If so, you could set up the Julia process with HTTP, ZMQ, etc. and warm the process during startup.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 4, 2021, 5:49pm UTC](https://discourse.julialang.org/t/how-can-i-speed-up-script-overhead-time/67676/6 "2021-09-04T17:49:26Z")

</div>

[JuliaCon 2020 | Julia for scripting | Fredrik Ekre - YouTube](https://youtu.be/IuwxE3m0_QQ) has some suggestions.
