# Make first call faster

**URL:** <https://discourse.julialang.org/t/make-first-call-faster/22845>\
**Category:** Performance\
**Tags:** ttfp\
**Created:** [April 6, 2019, 6:27pm UTC](https://discourse.julialang.org/t/make-first-call-faster/22845 "2019-04-06T18:27:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![KestutisMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kestutisma/32/7835_2.png) [@KestutisMa](https://discourse.julialang.org/u/KestutisMa)\
**Post date:** [April 6, 2019, 6:27pm UTC](https://discourse.julialang.org/t/make-first-call-faster/22845/1 "2019-04-06T18:27:28Z")

</div>

Hello, I just started using Julia, I noticed that commands  
`using Plotly plot(rand(10))`  
perform slowly ~30s in first run, but faster ~2s in second run.  
Could it be possible to cache that process to make it fast after Julia restart?

Kestutis,  
Lithuanian University of Health Sciences

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [April 6, 2019, 6:31pm UTC](https://discourse.julialang.org/t/make-first-call-faster/22845/2 "2019-04-06T18:31:13Z")

</div>

Hi @KestutisMa, welcome to Julia’s forums. Yes, we’re aware that time-to-first-plot is a major problem. It is being worked on and is one of the top priorities for compiler work:

> [@Compiler work priorities](https://discourse.julialang.org/t/compiler-work-priorities/17623):
>
> In response to I thought I might write a little post about the rough priorities of the compiler team: Correctness finding and fixing compiler and inference bugs Multithreading [non-copying task stack switching](https://github.com/JuliaLang/julia/pull/13099) (done) [new PARTR parallel runtime](https://github.com/JuliaLang/julia/pull/22631)[locks for I/O operations](https://github.com/libuv/libuv/issues/1595) other thread safety Compile-time latency, aka “the time-to-first-plot problem” making compilation faster caching more things Compiler-related packages and tools [PackageCompiler](https://github.com/JuliaLang/PackageCompiler.jl) Debugger [Cxx](https://github.com/Keno/Cxx.jl) type checking/linting J…

Compiler latency has already been improved significantly in Julia 1.1 and will be much better in the upcoming Julia 1.2 release.

---

<div class="post-metadata">

**Author:** ![traktofon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/traktofon/32/591_2.png) [@traktofon](https://discourse.julialang.org/u/traktofon)\
**Post date:** [April 8, 2019, 12:09pm UTC](https://discourse.julialang.org/t/make-first-call-faster/22845/3 "2019-04-08T12:09:57Z")

</div>

> [@StefanKarpinski](#):
>
> Compiler latency has already been improved significantly in Julia 1.1 and will be much better in the upcoming Julia 1.2 release.

Hi Stefan, could you give some more details about those upcoming improvements? Don’t see them mentioned in the NEWS.md on master, and I just tried

```julia
julia> VERSION
v"1.1.0"

julia> @time using PyPlot
  3.730215 seconds (7.85 M allocations: 410.184 MiB, 3.51% gc time)

julia> @time plot(rand(10))
  0.536229 seconds (1.48 M allocations: 74.613 MiB, 2.85% gc time)

```

vs

```julia
julia> VERSION
v"1.2.0-DEV.663"

julia> @time using PyPlot
  3.732857 seconds (7.53 M allocations: 393.297 MiB, 4.65% gc time)

julia> @time plot(rand(10))
  0.954086 seconds (3.75 M allocations: 187.505 MiB, 11.52% gc time)

```

which makes me think that these improvements are not in master yet. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![KestutisMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kestutisma/32/7835_2.png) [@KestutisMa](https://discourse.julialang.org/u/KestutisMa)\
**Post date:** [July 11, 2019, 5:08am UTC](https://discourse.julialang.org/t/make-first-call-faster/22845/4 "2019-07-11T05:08:30Z")

</div>

Are there still any improvements planned? 🙂

---

<div class="post-metadata">

**Author:** ![KestutisMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kestutisma/32/7835_2.png) [@KestutisMa](https://discourse.julialang.org/u/KestutisMa)\
**Post date:** [July 12, 2019, 5:13am UTC](https://discourse.julialang.org/t/make-first-call-faster/22845/5 "2019-07-12T05:13:46Z")

</div>

Julia **v1.2.0-rc2** during test is not exhibiting better compiler latency than **v1.1.1** :  
PyPlot:

```julia
[kest@archlinux ~]$ /home/kest/Downloads/julia-1.1.1/bin/julia -e '@time begin using PyPlot; plot(rand(5)); end'
  6.444096 seconds (9.40 M allocations: 487.974 MiB, 3.28% gc time)
[kest@archlinux ~]$ /home/kest/Downloads/julia-1.2.0-rc2/bin/julia -e '@time begin using PyPlot; plot(rand(5)); end'
  6.471744 seconds (9.06 M allocations: 470.050 MiB, 3.48% gc time)

```

Blink.jl:

```julia
[kest@archlinux ~]$ /home/kest/Downloads/julia-1.1.1/bin/julia -e '@time begin using Blink; w = Window(); end'
 12.486431 seconds (20.14 M allocations: 1020.407 MiB, 4.91% gc time)
[kest@archlinux ~]$ /home/kest/Downloads/julia-1.2.0-rc2/bin/julia -e '@time begin using Blink; w = Window(); end'
 12.884873 seconds (21.32 M allocations: 1.054 GiB, 5.07% gc time

```

Sorry, am I doing something wrong?

---

<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 12, 2019, 6:49am UTC](https://discourse.julialang.org/t/make-first-call-faster/22845/6 "2019-07-12T06:49:26Z")

</div>

> [@KestutisMa](#):
>
> Sorry, am I doing something wrong?

I don’t remember 1.2 having any dramatic impact on any load times.

---

<div class="post-metadata">

**Author:** ![fabgrei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabgrei/32/4214_2.png) [@fabgrei](https://discourse.julialang.org/u/fabgrei)\
**Post date:** [July 12, 2019, 7:53am UTC](https://discourse.julialang.org/t/make-first-call-faster/22845/7 "2019-07-12T07:53:24Z")

</div>

Depending on what packages you care about, you could try [https://github.com/JuliaLang/PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl)

It’s been tested for `Plots.jl` (`GR` backend), `DataFrames.jl`, `Query.jl`, `Makie.jl`. After you’ve compiled them (takes more than an hour if you compile all of the above), the packages load immediately and there is almost no waiting time until the first plot.

Caveat: Needs to be done after each update of a package, so it’s not useful for stuff you are developing.

I’ve used it for a while now and I’ve almost forgotten the time-to-first-plot issue 😉
