Adding modules in Julia script slows down the startup

When I run the following script:

#!/usr/bin/julia

using ArgParse
#using PyPlot
#using FortranFiles
#using BenchmarkTools
#using DiffEqBase
#using Parameters
#using LinearMaps
#using LineSearches

function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table s begin
        "--ex1"
            help = "Run example 1."
            action = :store_true
        "--ex2"
            help = "Run example 2."
            action = :store_true
        "--ex3"
            help = "Run example 3."
            action = :store_true
        "--plot", "-p"
            help = "Plotting ..."
            action = :store_true
    end

    return parse_args(s)
end

function main()
    parsed_args = parse_commandline()
    println("Parsed args:")
    for (arg,val) in parsed_args
        println("  $arg  =>  $val")
    end
end

main()

it takes about 2 sec to startup.

$ ./test_parset.jl
Parsed args:
  ex1  =>  false
  ex2  =>  false
  plot  =>  false
  ex3  =>  false

real	0m1.987s
user	0m1.921s
sys	0m0.228s

If now I uncomment the lines #using ..., I get a startup time 3 times slower.

Parsed args:
  ex1  =>  false
  ex2  =>  false
  plot  =>  false
  ex3  =>  false

real	0m6.402s
user	0m6.071s
sys	0m0.332s

Is this normal? Can I improve the speed somehow?

1 Like

Yep, this is normal. PyPlot.jl takes about 5s to load on my computer, DiffEqBase about 2s. There are some faster loading plotting packages though, GR.jl or UnicodePlots.jl. If you are really desperate, you can try to make a custom userimg.jl but that has many drawbacks.

I ran into the same problem today. It would be great if you could share the approach you end up following.