首页 > 解决方案 > Solutions to the gargantuan Julia interpreter startup time

问题描述

Currently, it takes a few seconds for the Julia interpreter to start on my machine when running any .jl file.

I'm wondering if there is a simple solution to this, such as a way to have a background pool of interpreters ready to execute scripts or a way to make the Julia repl, once opened, execute a .jl file (and possibly do so with the -p argument to properly handle multithreaded scripts) ?

标签: julia

解决方案


I'm wondering if there is a simple solution to this, such as [...] a way to make the Julia repl, once opened, execute a .jl file [...].

You can execute a .jl file in a running Julia REPL with the include() function. For example, to execute a file foo.jl, enter the Julia REPL and do:

julia> include("test.jl")

The file will then be executed within the REPL. However, this is unlikely to solve your problem, since the file execution will probably take multiple seconds as well. The REPL itself starts quickly, the long execution time stems from Julia taking a long time to load the file.

You can partially address this issue with Revise.jl. Revise.jl is a Julia package that automatically and quickly reloads your imported files and packages when they are edited. Thus, you could mitigate your issue by only having to load the .jl file once at startup. Here is a quick example of using Revise.jl:

julia> Pkg.add("Example")
INFO: Installing Example v0.4.1
INFO: Package database updated

julia> using Revise        # importantly, this must come before `using Example`

julia> using Example

julia> hello("world")
"Hello, world"

推荐阅读