使用和包含的并行性,或者至少是更快的方法?

Parallelism of Using and include, or at least, faster ways?

我开始有一个大项目,我目前正在使用并包含许多包和 .jl 文件:

a = time()
@info "Loading JuMP"
using JuMP
@info "Loading Gurobi"
using Gurobi
# @info "Loading Combinatorics, DelimitedFiles, Dates and StatsBase"
# using Combinatorics, DelimitedFiles, Dates, StatsBase
@info "Loading Combinatorics, DelimitedFiles, Dates and Random"
using Combinatorics, DelimitedFiles, Dates, Random
@info "Loading Distributions, Graphs, GraphsFlows[TODO] and Plots"
using Distributions
# using Graphs, GraphsFlows, GraphPlot, Plots
using Graphs, GraphPlot, Plots
@info "Loading Parameters and Formatting"
using Parameters, Formatting #
@info "Loading Compose, Cairo and Fontconfig"
using Cairo, Fontconfig, Compose
@info "Loading .jl files $(lpad("0%",4))"

include("write_tikz.jl")
include("with_kw_mutable_structures.jl")
include("instance.jl")
include("solution_checker.jl")
@info "Loading .jl files $(lpad("25%",4))"
include("create_subtour_constraint.jl")
# include("ilp_rho_rsp_st_chains.jl")
include("ilp_rho_rsp_without_uc.jl")
include("benders_rho_rsp.jl")
include("benders_subproblem_poly.jl")
@info "Loading .jl files $(lpad("50%",4))"
include("benders_subproblem_ilp_primal.jl")
include("benders_subproblem_ilp_dual.jl")
include("print.jl")
include("three_four_rho_rsp.jl")
@info "Loading .jl files $(lpad("75%",4))"
include("utilities.jl")
include("rho_rsp_lb.jl")
include("./plots/plots.jl")
include("local_searches.jl")
@info "Loading .jl files $(lpad("100%",4))"
@info time()-a

所有这些 usingincludes 每次启动 Julia 需要 34 秒。已经编译的时候确实更快,第二次做include("main.jl"),但是已经编译一次还是需要2s45。

我想知道是否有更快的方法来 using 包和 includes Julia 文件,也许是并行的?

我正在使用 Julia 1.7.2

这些是要考虑的步骤

  1. 将您的所有代码打包到一个 Julia 包中。 Julia 包将在第一次使用时预编译,后续时间会短得多。您不希望拥有包含如此多内容的代码 - 制作一个程序包以加快速度。
  2. 很可能在步骤 (1) 之后您会没事的。然而,下一个选项是使用 PackageCompiler 将包编译到 Julia 系统映像中。
  3. 正如@jing 所提到的,每个新的 Julia 版本都将在更短的时间内完成这项工作