Very slow Plots performance and... no plot

Environment: openSUSE 15.1, downloaded Julia 1.5.2 (tar.gz).

I’m finding that using Plots (pun sort of intended) is really slow and when I use plot() in a script I get no output:

#plottest
using Dates
t0 = now()
using Plots
t1 = now()
plot( [ cumsum( rand( 50 ) .- 0.5 ), cumsum( rand( 50 ) .- 0.5 ) ] )
t2 = now()
println( "using Plots took: ", t1 - t0 )
println( "plot() took: ", t2 - t1 )
println( "Overall: ", t2 - t0 )

When running this as in a terminal, I get:

$ time julia ./plottest
using Plots took: 11862 milliseconds
plot() took: 3847 milliseconds
Overall: 15709 milliseconds

real	0m15.876s
user	0m15.495s
sys	0m0.392s
$

If I include a “shebang” (either “#!/usr/bin/julia” or “#!/usr/bin/env julia”) in the script and run it, I get the same results: slowness and no plot. I’m only able to produce a plot when running julia interactively. (Not how I anticipated running Julia code long term.)

Q1: Is it normal for “using Plots” to take 10+ seconds when a script runs? Even working interactively, “using Plots” takes ~10s to complete. Plus, 3.8 seconds to plot 2 50-point data sets seems excessive as well. (Maybe cumsum() is the problem in that case?)

Q2: Why is no plot ever produced when plot() is run from a script? I only get the output from plot() when working at the “julia>” prompt.

TIA…

Yes, it is. A lot of Plots functions get compiled on the first call of the package, and that takes some seconds. If you need to plot interactively keep you Julia section open. The second time you plot something (your second call to plot(…)) will be fast. This is getting better at each release, but still is not ideal.

When running from a script the plot is not shown interactively, because the script ends. You might want to add

savefig("./plot.pdf")

to save plot generated before the end of the script.

1 Like

Note that 1.6 should be at least 2x faster for time to load plots (the exact difference will depend on hardware and OS)

You’d need to call display on the plot object in a script to display the plot and then you’d need something to stop the script from terminating, like a readline at the end of the script. Otherwise you will see the plot only for a few microseconds.

1 Like

You may also want to check out the PackageCompiler package, it allows you to create a so-called sysimage that greatly speeds up the package loading and compilation.

1 Like

I suspected that it would be something like that. I’ll give a try in a few minutes.

Thanks.

Good to know that better things are coming. Thanks…

I haven’t gotten far enough into Julia to think about compilation but it is something that attracted me to the language. I’ll give that a look. Thanks…

Julia is still best uses interactively but if you do want to use Julia for scripting I’d consider DaemonMode.jl.
The second time you run the plot script should be fast, just like the second time you plot from the REPL.