# Reducing package loading time

**URL:** https://discourse.julialang.org/t/reducing-package-loading-time/42774
**Category:** General Usage
**Created:** [July 9, 2020, 6:35am UTC](https://discourse.julialang.org/t/reducing-package-loading-time/42774 "2020-07-09T06:35:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)
#### Post date: [July 9, 2020, 6:35am UTC](https://discourse.julialang.org/t/reducing-package-loading-time/42774/1 "2020-07-09T06:35:57Z")

</div>

I run my Julia application as:

```julia
julia st.jl

```

The `st.jl` file starts with:

```julia
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.

---

<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: [July 9, 2020, 6:46am UTC](https://discourse.julialang.org/t/reducing-package-loading-time/42774/2 "2020-07-09T06:46:16Z")

</div>

You can create a sysimage with this packages preloaded into it: [https://julialang.github.io/PackageCompiler.jl/dev/sysimages/](https://julialang.github.io/PackageCompiler.jl/dev/sysimages/).

---

<div class="post-metadata">

### Author: ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)
#### Post date: [July 9, 2020, 6:32pm UTC](https://discourse.julialang.org/t/reducing-package-loading-time/42774/3 "2020-07-09T18:32:54Z")

</div>

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

```julia
create_sysimage([:StaticArrays, :LoopVectorization, :SIMD, :Formatting, :BSON]; sysimage_path="image1.so")

```

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

```julia
paul@extra:~/st/julia/image1$ julia -q -Jimage1.so
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.

```

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [July 9, 2020, 7:10pm UTC](https://discourse.julialang.org/t/reducing-package-loading-time/42774/4 "2020-07-09T19:10:48Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)
#### Post date: [July 10, 2020, 12:43am UTC](https://discourse.julialang.org/t/reducing-package-loading-time/42774/5 "2020-07-10T00:43:08Z")

</div>

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?
