# Save complete session snapshot?

**URL:** <https://discourse.julialang.org/t/save-complete-session-snapshot/24537>\
**Category:** Tooling\
**Created:** [May 23, 2019, 7:08pm UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537 "2019-05-23T19:08:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [May 23, 2019, 7:08pm UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/1 "2019-05-23T19:08:20Z")

</div>

I keep wondering why the time-to-first-whatever is such a difficult problem. It is currently my main issue with Julia by a fair margin (I do know about Revise and PackageCompiler, but also about their limitations). There is clearly something I don’t understand, and would appreciate some insights.

If I have a REPL session running, with a bunch of compiled methods in memory, why is it not possible to save a complete state of my session, with all its definitions and llvm bytecodes, from memory onto a file? Wouldn’t that be a generic approach to solve the problem? (My wishful dream would be that I could just load a certain work snapshot from a file, with a selection of my favourite packages already loaded and a large set of important methods precompiled, and immediately start to compute and plot stuff without precompilation delays…)

---

<div class="post-metadata">

**Author:** ![haberdashPI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haberdashpi/32/26337_2.png) [@haberdashPI](https://discourse.julialang.org/u/haberdashPI)\
**Post date:** [May 23, 2019, 8:10pm UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/2 "2019-05-23T20:10:23Z")

</div>

Isn’t that basically what `Revise` and `PackageCompiler` already allow for? My understanding is that the same limitations would apply to any approach that saved the compilation state: i.e. you couldn’t redefine types saved in this image (ala `Revise`) and there may be existing compiler bugs/limitations revealed by this approach (ala `PackageCompiler`).

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [May 23, 2019, 8:49pm UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/3 "2019-05-23T20:49:54Z")

</div>

Well, Revise doesn’t survive reboots and PackageCompiler doesn’t work with a whole workspace (which can have several non-trivially interacting packages loaded), and is tricky to get to work in general, AFAIU.  
So this is an honest question, I really have the feeling there is some core aspect of Julia’s design that makes this snapshot saving problematic, but I don’t know what it is…

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 24, 2019, 5:48am UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/4 "2019-05-24T05:48:53Z")

</div>

> [@pablosanjose](#):
>
> Wouldn’t that be a generic approach to solve the problem?

I think this would be a workaround, not a solution. AFAIK the core devs prefer [finding a general solution](https://discourse.julialang.org/t/compiler-work-priorities/17623).

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [May 24, 2019, 6:01am UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/5 "2019-05-24T06:01:29Z")

</div>

Oh! So you think it _would_ be possible?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 24, 2019, 6:29am UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/6 "2019-05-24T06:29:16Z")

</div>

I don’t think that’s the right question. It may not be _impossible_, but it would surely be a lot of work for a very specific purpose, and making compilation faster would have more general benefits.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [May 24, 2019, 6:49am UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/7 "2019-05-24T06:49:34Z")

</div>

Understood, thanks @Tamas_Papp. But my point is, making compilation faster (i.e. faster inference + caching more things) is different from making it instantaneous (i.e. caching all things)… The latter would undoubtedly also have its appeal.

In any case: is there any open Github issue (analogous to the PARTR one) tracking ideas/work towards the goal of faster compilation? Or should I just look at the `latency` tag? I haven’t seen any specific strategy spelled out (it might be happening behind the scenes, of course)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 24, 2019, 7:00am UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/8 "2019-05-24T07:00:27Z")

</div>

> [@pablosanjose](#):
>
> is there any open Github issue (analogous to the PARTR one) tracking ideas/work towards the goal of faster compilation?

Use tags, eg

> **[Issues · JuliaLang/julia](https://github.com/JuliaLang/julia/labels/latency)**
>
> The Julia Programming Language. Contribute to JuliaLang/julia development by creating an account on GitHub.

> [@pablosanjose](#):
>
> it might be happening behind the scenes, of course

AFAIK all concrete problems and solutions are discussed openly, as issues and PRs.

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [May 24, 2019, 12:32pm UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/9 "2019-05-24T12:32:35Z")

</div>

Actually, there is one that I’m watching that’s not yet a PR to the JuliaLang repo: [julia/test/standalone-aot at standalone-mode · tshort/julia · GitHub](https://github.com/tshort/julia/tree/standalone-mode/test/standalone-aot)

This branch lets one compile (small, simple) programs to native code as an executable, in an AOT manner like PackageCompiler, but uses an approach that is much closer to how CUDAnative works. You could feasibly use this branch, plus some hooks into codegen to record all new method definitions and such, and then compile those to an executable that can be later run to get you back into a state that closely matches the one you used to be in.

Of course, it’s not possible to save things like open network sockets and pointers to unknown C objects.

---

<div class="post-metadata">

**Author:** ![TsurHerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tsurherman/32/1234_2.png) [@TsurHerman](https://discourse.julialang.org/u/TsurHerman)\
**Post date:** [May 25, 2019, 7:18pm UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/10 "2019-05-25T19:18:01Z")

</div>

Try

> **[GitHub - TsurHerman/Fezzik: Brute force sysimg building for Julia](https://github.com/TsurHerman/Fezzik)**
>
> Brute force sysimg building for Julia. Contribute to TsurHerman/Fezzik development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 26, 2019, 8:18am UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/11 "2019-05-26T08:18:33Z")

</div>

Saving a snapshot is pretty much exactly how the sysimg that is shipped with Julia is built.

> <https://github.com/JuliaLang/julia/blob/e39f498aca58abb8aecac34d329d7de9a0cead02/sysimage.mk#L75-L82>

in the Makefile and the `contrib/generate_precompile.jl` is what we put into the sysimg:

> <https://github.com/JuliaLang/julia/blob/master/contrib/generate_precompile.jl>

Where the REPL gets started, a few things gets evaluated and some Pkg commands are run. Then a snapshot of that is saved.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [May 27, 2019, 8:29am UTC](https://discourse.julialang.org/t/save-complete-session-snapshot/24537/12 "2019-05-27T08:29:07Z")

</div>

I had not really succeeded in using PackageCompiler until now, but I now get it! It is indeed a great solution, once you get it to run. I guess if you have no binary deps it is much smoother. I wish I could mark two posts as solutions, Fezzik also looks great.
