# 'using Plots' takes 20 seconds or more

**URL:** <https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061>\
**Category:** Performance\
**Tags:** plotting\
**Created:** [November 14, 2017, 8:12am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061 "2017-11-14T08:12:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [November 14, 2017, 8:12am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/1 "2017-11-14T08:12:33Z")

</div>

I’ve read that calls to `using Plots` can sometimes be slow but I wonder if as slow as I’m seeing is normal. On 3 trials after starting Julia from the command line I `@time`d this taking between 35 and 40 seconds.

After some Googling, I learned how to [build](http://www.stochasticlifestyle.com/7-julia-gotchas-handle/) my system image. After doing that I’m getting more like 19.7 seconds so that definitely makes a difference but 20 seconds still seems awfully long.

Also of note, using `-j 2` tends to approximately _double_ the time to run the `using` command.

Is there something I’m missing or is this just par for the course?

```julia
Julia Version 0.6.1
Commit 0d7248e (2017-10-24 22:15 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
  WORD_SIZE: 64
  uname: Darwin 16.7.0 Darwin Kernel Version 16.7.0: Wed Oct 4 00:17:00 PDT 2017; root:xnu-3789.71.6~1/RELEASE_X86_64 x86_64 i386
Memory: 8.0 GB (605.25 MB free)
Uptime: 1.069672e6 sec
Load Avg: 2.2373046875 2.3759765625 2.30517578125
Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz: 
       speed user nice sys idle irq
#1 2400 MHz 625768 s 0 s 393018 s 2275837 s 0 s
#2 2400 MHz 329560 s 0 s 164461 s 2800507 s 0 s
#3 2400 MHz 620082 s 0 s 329063 s 2345384 s 0 s
#4 2400 MHz 340340 s 0 s 168468 s 2785719 s 0 s

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 14, 2017, 8:37am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/2 "2017-11-14T08:37:58Z")

</div>

It’s a known problem.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [November 14, 2017, 8:41am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/3 "2017-11-14T08:41:01Z")

</div>

Using master of Plots.jl is faster as it is precompiled, but still slow:

```julia
julia> @time using Plots                                                                                                                                                 
  6.168379 seconds (4.04 M allocations: 219.459 MiB, 1.31% gc time)                                                                                                      
                                                                                                                                                                         
julia> @time plot(1:3)                                                                                                                                                   
 16.983929 seconds (10.69 M allocations: 569.126 MiB, 1.96% gc time)                                                                                                     

```

then it still takes another 6s or so for the plot to show (pyplot backend). I use PyPlot.jl because I can’t be bothered to wait; that takes about 6s to first plot.

You should be able to make it fast (\<1s) with a custom userimg. But for that you need to make sure all the important functions get compiled. Have a look at the readme of SnoopCompile.

---

<div class="post-metadata">

**Author:** ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)\
**Post date:** [November 14, 2017, 10:21am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/4 "2017-11-14T10:21:30Z")

</div>

I should write a tutorial on how to use Plotly,js with Pages.js. There is an undocumented Plotly.js example in Pages.jl (master). It is super fast and interactive 👍

Edit: I should qualify “super fast” with this group 😅 I did not compare to other packages so it was more of an absolute statement about general satisfaction with the speed. I wouldn’t try anything super complicated and expect great performance. There are other great packages that are probably faster the plotly 🙂

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 14, 2017, 12:43pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/5 "2017-11-14T12:43:25Z")

</div>

I’ve been working on this problem in MakiE, which is a new design prototype for Plots, with only the glvisualize backend for now.  
I just did the following benchmarks:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/d/0ddddaa933869477158c7ff5fe39b2c2d9ac823d.png)

Plotting one million points in 3s start to end 🙂

The trick is to make your package precompile save and use snoop compile, to emit precompile statements to tell julia what functions to compile binary for, when included in the system image.

I will create a package and instructions for what I did to make loading fast! This could be part of Pkg.build().

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 14, 2017, 2:51pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/6 "2017-11-14T14:51:17Z")

</div>

Whaaat??? This looks like a game-changer!

[EDIT: for comparison, something like this takes like 4.7 seconds in Mathematica (3,3GHz Core i7)]

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [November 14, 2017, 3:17pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/7 "2017-11-14T15:17:42Z")

</div>

Mathematica used to take 30 seconds to start up when I last used it. (Old iMac.) perhaps it’s preloading the `Plot[]` code 😀

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 14, 2017, 4:00pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/8 "2017-11-14T16:00:04Z")

</div>

Of course, it’s 4.7 seconds _after_ starting Mathematica (v11), which makes this comparison all the more striking. I really hope Simon is able to keep the performance at this level as he continues to flesh out MakiE. @sdanisch, is it reasonable to expect that the `libuserimg.so` approach could remain transparent to the user, and indeed make it part of the `Pkg.build()` process?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 14, 2017, 4:04pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/9 "2017-11-14T16:04:44Z")

</div>

For Makie I plan to have a Pkg.build() process, which can be steered by environment variables for now.  
I will see @StefanKarpinski thinks about integration into Pkg3. From all I heard, the plan is to improve caching of compiled binary for Julia in 1.0, so maybe this will become a natural part of Julia anyways.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 14, 2017, 4:10pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/10 "2017-11-14T16:10:53Z")

</div>

That would be awesome! It really pains me every time google spits back at me [that old article](http://zverovich.net/2016/05/13/giving-up-on-julia.html) complaining about precompilation times in Julia.

---

<div class="post-metadata">

**Author:** ![gangchern](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gangchern/32/13298_2.png) [@gangchern](https://discourse.julialang.org/u/gangchern)\
**Post date:** [April 14, 2020, 6:02pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/11 "2020-04-14T18:02:14Z")

</div>

Does this problem solved now?  
2020/04/14

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 14, 2020, 7:49pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/12 "2020-04-14T19:49:00Z")

</div>

As of 1.4, I get 6 seconds (after precompile), so not fully fixed yet but about 3x better. It’s still improving though. 1.4 is better than 1.3, and 1.5 will be better than 1.4 was.

---

<div class="post-metadata">

**Author:** ![gangchern](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gangchern/32/13298_2.png) [@gangchern](https://discourse.julialang.org/u/gangchern)\
**Post date:** [April 15, 2020, 4:59pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/13 "2020-04-15T16:59:57Z")

</div>

really good news.

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [April 15, 2020, 5:56pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/14 "2020-04-15T17:56:58Z")

</div>

[Gnuplot.jl](https://github.com/gcalderone/Gnuplot.jl) (master branch, new release due in a few days) takes ~5 seconds with the default `qt` terminal, and no precompilation or modified system image:  
 ![Screenshot_20200415_195448](https://global.discourse-cdn.com/julialang/original/3X/3/0/30036412619c67276df07546611c6d51c3d5e172.png).

but uses [gnuplot](http://gnuplot.sourceforge.net/) as backend…

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [April 15, 2020, 6:10pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/15 "2020-04-15T18:10:45Z")

</div>

Just one more data point… [Gaston](https://mbaz.github.io/Gaston.jl/v0.10.0/) master (precompiled):

```julia
$ time julia -e 'using Gaston; plot(randn(10^6),randn(10^6))'

real	0m1.000s
user	0m1.168s
sys	0m1.379s

```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [April 16, 2020, 2:04am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/16 "2020-04-16T02:04:27Z")

</div>

I can confirm that both Gaston and Gnuplot are very capable. And FAST. I highly recommend this to anyone who is looking for fast plotting. Knowledge of gnuplot is a plus, of course, but for someone programming in Julia that shouldn’t be a problem.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [April 16, 2020, 2:46pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/17 "2020-04-16T14:46:57Z")

</div>

Plots has good speed on the second plot as we all know, unlike the (slight) second-plot issue I discovered with another package:

[https://github.com/mbaz/Gaston.jl/issues/133](https://github.com/mbaz/Gaston.jl/issues/133)

There’s no real need to do this redundantly (might still happen in real-world code), but `using` only gets stable (allocations/speed) on third use (unlike for Gaston, where it only applies to the plot):

```julia
julia> @time using Plots
  9.869769 seconds (7.44 M allocations: 422.704 MiB, 2.78% gc time)

julia> @time using Plots
  1.492128 seconds (1.70 M allocations: 80.019 MiB, 1.90% gc time)

julia> @time using Plots
  0.000298 seconds (276 allocations: 14.859 KiB)

```

---

<div class="post-metadata">

**Author:** ![Volker\_Weissmann](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Volker\_Weissmann](https://discourse.julialang.org/u/Volker_Weissmann)\
**Post date:** [November 17, 2020, 12:22am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/18 "2020-11-17T00:22:29Z")

</div>

Is this issue still actively worked on?

@time using Plots  
11.354988 seconds (18.48 M allocations: 1.024 GiB, 3.34% gc time)

> $ time julia -e “using Plots”
> 
> real 0m11,482s  
> user 0m10,651s  
> sys 0m0,373s

> $ time python -c “import matplotlib”
> 
> real 0m0,868s  
> user 0m0,411s  
> sys 0m0,264s

> $ time gnuplot -e “”
> 
> real 0m0,026s  
> user 0m0,023s  
> sys 0m0,003s

I thought Julia wanted to rival C’s speed, not be slower than python.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [November 17, 2020, 12:25am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/19 "2020-11-17T00:25:49Z")

</div>

What version are you on? On Master, I’m seeing 3 seconds, which while not solved, is a massive improvement. (`time julia -e “using Gaston”` also clocks in at just over 1 second for me)

---

<div class="post-metadata">

**Author:** ![Volker\_Weissmann](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Volker\_Weissmann](https://discourse.julialang.org/u/Volker_Weissmann)\
**Post date:** [November 17, 2020, 12:32am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/20 "2020-11-17T00:32:08Z")

</div>

I’m using the latest version that Arch Linux ships: julia version 1.5.3

> $ time julia -e “using Gaston”
> 
> real 0m1,743s  
> user 0m1,580s  
> sys 0m0,146s

[Next page](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061.md?page=2)
