-
-
Notifications
You must be signed in to change notification settings - Fork 285
Description
Issue
Using a custom sysimage can drastically reduce load times of packages. The goto solution for this is PackageCompiler.jl and it works well but it isn't used as much as perhaps warranted considering the benefits it provides. From some discussion, it seems that it is a bit too much of a "mental overhead" to use it. To use PackageCompiler.jl for a sysimage it requires you to:
- Install the package
- Manually list the packages you want to precompile into a sysimage
- Make sure you start Julia with that sysimage
- Make sure you update the sysimage when your dependencies update or you will load old versions of everything.
There is currently no way to automatically detect this. - For best effect, also provide a "precompilation execution script" that is used to gather data of what functions to precompile.
Since load time of packages and "time to first plot" are a frequent gripe about Julia, it makes sense to see if
we can give a better interface to PackageCompiler.
Proposal
The proposal here is to introduce a new set of Pkg API that handles sysimages. To give a taste of what a session would look like:
pkg> sysimage create
Info: Creating a new sysimage based on the packages in curent project at `~/.julia/environments/v1.5/Project.toml`
Packages tracked by path and their dependencies not put into sysimage:
- OhMyREPL
└ DataStructures, Crayons
Info: Package `OhMyREPL` not put into sysimage because it is tracked by path. This caused its dependencies `OrderedCollect
pkg> sysimage status
(@v1.5) pkg> status
Status `~/.julia/environments/v1.5/sysimage.dylib`
[6e4b80f9] BenchmarkTools v0.5.0
[f68482b8] Cthulhu v1.2.0
[0c46a032] DifferentialEquations v6.15.0
[7876af07] Example v0.5.3
[8fb92a4a] Exfiltrator v0.1.0
[b22a6f82] FFMPEG_jll v4.3.1+2
Package in project not in sysimage
[6e4b80f9] OhMyREPL v0.7.0 `~/JuliaPkgs/OhMyREPL.jl`
[ae3bc0f9] DataStructures v0.5.0
[a8cc5b0e] + Crayons v4.0.4
pkg> up
Updating `~/.julia/environments/v1.5/Project.toml`
[a8cc5b0e] + Crayons v4.0.4
Updating `~/.julia/environments/v1.5/Manifest.toml`
[a8cc5b0e] ↑ Crayons v4.0.3 ⇒ v4.0.4
pkg> sysimage status
Warn: Some packages in the sysimage are out of date with project, run `sysimage update` to update it:
[a8cc5b0e] ↑ Crayons v4.0.3 ⇒ v4.0.4
...
pkg> sysimage update
...
Next time we start julia:
> julia --project
❯ /usr/local/bin/julia -q
Info: Automatically using sysimage at `~/.julia/environments/v1.5/sysimage.dylib`
julia> @time using DifferentialEquations # look how fast
0.0202 seconds (144.73 k allocations: 7.456 MiB)
So the concrete proposal here is to add convenience functionalities to Pkg to make dealing with sysimage easier.
In addition, this proposes adding some functionality to Julia itself that allows it to automatically detect a custom sysimage next to the project and use that for the Julia process. This could be done via some naming convention.
Why in Pkg and not in a separate package.
The main point of this proposal is to reduce the friction in using e.g. PackageCompiler. Bundling it with Pkg allows it to use the super user-friendly Pkg REPL with no need to manually install anything. Also, we likely want to use a lot of the code in Pkg for dealing with projects, for status printing, etc so from that point of view, it makes sense to have it in Pkg. One question is if the code for PackageCompiler itself should move into Pkg. I think it is best to not do this but instead, just install PackageCompiler into the global project from Pkg when the sysimage command is used for the first time.
Possible complications:
- Sysimages are not usable across different Julia versions. Right now, upgrading the Julia minor version is super easy. With a custom sysimage one needs to refresh all the sysimages.
- Creating a sysimage requires a compiler. PackageCompiler provides a compiler via the artifact system on Windows and tries to use a local one on mac/linux. We could just ship a compiler via the artifact system on Mac and Linux as well if there are problems with using the system one.
- If one has a custom sysimage for the default environment, starts julia, changes the environment, and then start loading packages, packages from the sysimage for the default environment will still be "locked-in". Pkg could warn about this when a new project is activated.
cc @tkf since I think you have thought a bit about stuff like this