What is harder about saving a Julia session via the REPL whenever?

I’m learning PackageCompiler.jl, and I’m wondering why creating a sysimage requires an input of packages, the project/environment, and precompile scripts. I do appreciate the paper trail, but couldn’t a sysimage be created from a session on the fly, like calling savesessionto(file) in the REPL?

This thread gave me the impression that such a session snapshot is possible and actually done for base Julia. However, I read issue #22598 from 2017 that “it seems to be technically nearly impossible to do this because of the large amount of program state which cannot be persisted or restored across processes.” Is that still true? If so, how does PackageCompiler manage to do it with the aforementioned stipulations? If not, why isn’t savesessionto standard issue?


I spent a small amount of time a while ago trying to make this work.

Here’s my WIP rebased: add exit_save_sysimage · IanButterworth/julia@454090a · GitHub

One of the issues I came up against, IIUC, was that the output process needs all tasks to be finished. This was crashing during serialization of active tasks.

It might be worth giving it a go to see what it hits.


For instance

% ./julia --startup-file=no -e 'Base.exit_save_sysimage("f.so")'
[ Info: Julia exiting. A sysimage will be generated at "/Users/ian/Documents/GitHub/julia/f.so"
ERROR: Task cannot be serialized
 [1] exit
   @ ./initdefs.jl:28 [inlined]
 [2] exit
   @ ./initdefs.jl:29 [inlined]
 [3] exit_save_sysimage(fpath::String)
   @ Base ./output.jl:14
 [4] top-level scope
   @ none:1

Here is a list of sources of global state separate-compilation.md · GitHub

1 Like