How can I speed up script overhead time?

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

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?!

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 If you really need to run a script again and again use https://github.com/dmolina/DaemonMode.jl .

2 Likes

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?

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

3 Likes

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.

1 Like

JuliaCon 2020 | Julia for scripting | Fredrik Ekre - YouTube has some suggestions.

2 Likes