Reducing package loading time

I run my Julia application as:

julia st.jl

The st.jl file starts with:

t0 = time_ns()

using StaticArrays, LoopVectorization
using SIMD, Formatting
using BSON: @save, @load

t1 = time_ns()

It takes over 3s for this part to execute. Is there an easy way to reduce this time? Building a self-contained binary including Julia and st.jl is acceptable, if it is not too complicated.

You can create a sysimage with this packages preloaded into it:


I’m following an example shown there and I run into a glitch. I’ve built an image with this command:

create_sysimage([:StaticArrays, :LoopVectorization, :SIMD, :Formatting, :BSON]; sysimage_path="")

which went fine and created When I try to use it, Julia can’t find StaticArrays, which is on the list of compiled modules. ~/st/julia/image1 directory contains Manifest.toml Project.toml.

paul@extra:~/st/julia/image1$ julia -q
julia> Base.loaded_modules
Dict{Base.PkgId,Module} with 47 entries:
  StaticArrays [90137ffa-7385-5640-81b9-e52037218182]        => StaticArrays

julia> using StaticArrays
ERROR: ArgumentError: Package StaticArrays not found in current path:
- Run `import Pkg; Pkg.add("StaticArrays")` to install the StaticArrays package.

Another option is to call julia --compile=min st.jl this can be much faster if the bottleneck of your code is compiling methods that are called a single time, and much slower if the bottleneck is actually doing the computations.

I tried with julia-1.5.0-rc1 and it works now. The time spent in using section went down to 1ms. The only difference from previous attempt was to add all required packages to the default project before activating a new project (image1) and adding them again. Was this necessary?

1 Like