Daniel YC Lin
Daniel YC Lin

Reputation: 15992

How to speed up julia script launch time

I've wrote a script to plot daily data in Julia, but I found it run slow. Seems no ideal method to speed it up.

for example foo.jl

#!/bin/bash
#=
exec julia -O0 --compile=min "${BASH_SOURCE[0]}" "$@"
=#

using UnicodePlots, CSV, DataFrames, Chain, Dates
...

I wish if first time I run 'foo.jl a.csv b.csv", it may takes time to compile/load (10 seconds). And the 2nd time I run it, it can skip the compile process.(It should be around 3 seconds).

Is it possible now? I'm use version 1.8.3. Or, can I setup those packages which I used as default required compiled every time I launch julia to speed it up?

Upvotes: 5

Views: 1023

Answers (2)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42194

You need to create a system image and give this a parameter each time when starting Julia:

using PackageCompiler
create_sysimage(["UnicodePlots, CSV, DataFrames, Chain"], sysimage_path="sys_foo.so", precompile_execution_file="script_with_your_typical_workflow.jl")

After this is done you will need to run your code as:

julia --sysimage sys_foo.so foo.jl

For more information see this thread: Julia seems to be very slow

Upvotes: 6

Nils Gudat
Nils Gudat

Reputation: 13800

While I believe Przemyslaw's answer is the best advise at this point, I'd like to add two points:

  • Another option is to use the DaemonMode.jl package, which implements a client/server model to keep compiled code in memory.

  • Also, the "time to first X" latency problem has been a high priority for the core language devs for a long time, and it appears at the time of writing that we might start to see material improvements in Julia versions 1.9 and 1.10 towards native code caching. A variety of other avenues for addressing the issues are being pursued more or less actively in parallel, so if you are a reader from 2023 or later building sysimages might not be required any longer.

Upvotes: 5

Related Questions