Why julia takes long time to import a package?
You can do two things to reduce the latency:
- Use Julia 1.5.0 (beta as of today) - it dynamically allows to use different optimization levels for packages and
Plots.jl
is making use of that reducing the time-to-first-plot by more than half. This is indeed a low hanging fruit - update the Julia. Here are the measurements on my laptop:
julia> @time using Plots
16.816181 seconds (14.46 M allocations: 854.353 MiB, 2.31% gc time)
julia> @time Plots.plot(sin.(1:0.25:7))
4.292128 seconds (4.70 M allocations: 243.866 MiB, 2.01% gc time)
# this waits another 7s before the plot actually appears on screen
Those times are not excellent but acceptable.
- Build
Plots
into your system image (for details see https://julialang.github.io/PackageCompiler.jl/dev/examples/plots/)
using PackageCompiler
create_sysimage(:Plots, sysimage_path="sys_plots.so", precompile_execution_file="precompile_plots.jl")
This reduces your time-to-first-plot below half second. Has also a disadvantage that the Julia interpreter (REPL) takes 400ms more time to start and you need to use the flag --sysimage sys_plots.so
(or --sysimage sys_plots.dll
on Windows) when starting Julia. Precompiling packages can sometimes bring other caveats too (e.g. package updating each time requires recompiling etc.).