# Time to first plot with system image not as good as expected

**URL:** https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428
**Category:** General Usage
**Tags:** question, autosysimages
**Created:** [September 18, 2022, 11:14am UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428 "2022-09-18T11:14:17Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [September 18, 2022, 11:14am UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/1 "2022-09-18T11:14:17Z")

</div>

I am trying to reduce the time-to-first-plot by using a system image. What I am doing is explained in detail here: [GitHub - ufechner7/Plotting: Demo for using InspectDR](https://github.com/ufechner7/Plotting)

If you are using Linux you can easily reproduce my results.

Without system image:

```julia
ufechner@TUD277255:~/repos/Plotting$ julia --project
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.8.1 (2022-09-06)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> @time include("src/plot.jl")
To zoom, draw a rectangle while keeping the right mouse key pressed!
To go back to see the full graph, press <CTRL><f>
 15.647398 seconds (38.22 M allocations: 2.047 GiB, 4.96% gc time, 79.17% compilation time: 12% of which was recompilation)

```

With system image:

```julia
ufechner@TUD277255:~/repos/Plotting$ asysimg --project
┌ Info: The package AutoSysimages.jl started!
│ Loaded sysimage: /home/ufechner/.julia/asysimg/1.8.1/23ZRuw/asysimg-2022-09-18T12-39-40.634.so
│ Active directory: /home/ufechner/.julia/asysimg/1.8.1/23ZRuw
│ Global snoop file: /home/ufechner/.julia/asysimg/1.8.1/23ZRuw/snoop-file.jl
└ Tmp. snoop file: /tmp/jl_1yJIleFuBE-snoop.jl
┌ Warning: Function 'pkgversion' is needed to check versions.
└ @ AutoSysimages ~/.julia/packages/AutoSysimages/LTaGS/src/AutoSysimages.jl:375
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.8.1 (2022-09-06)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

asysimg> @time include("src/plot.jl")
To zoom, draw a rectangle while keeping the right mouse key pressed!
To go back to see the full graph, press <CTRL><f>
  7.374812 seconds (20.07 M allocations: 1.012 GiB, 7.48% gc time, 99.52% compilation time)

```

Why do I have still 99.5% compilation time even though I am using a system image?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [September 18, 2022, 1:42pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/2 "2022-09-18T13:42:54Z")

</div>

Could it be that the fact that I am using Gtk.shortNames, but Gtk is in the Project.toml file confuses AutoSysimages or PackageCompiler?

```julia
using Gtk.ShortNames, InspectDR

function init()
    inspectdr()
    InspectDR.defaults.xaxiscontrol_visible = false
    default(width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12)
end

function plot(params...; keywords...)
    p = Plots.plot(params...; keywords...)
    pIDR = display(p) # Display with InspectDR and keep plot object
    resize!(pIDR.wnd, 1200, 700) # Resize GTK window directly
    G_.keep_above(pIDR.wnd, true)
end

```

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [September 18, 2022, 5:35pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/3 "2022-09-18T17:35:46Z")

</div>

How much snoopprecompilation is setup in InspectDR?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [September 18, 2022, 5:38pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/4 "2022-09-18T17:38:42Z")

</div>

But why should that matter? AutoSysimage is recording the commands I executed on the command line…

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [September 18, 2022, 5:41pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/5 "2022-09-18T17:41:18Z")

</div>

Does it have the special handling of dynamic dispatching code that SnoopPrecompile.jl has? Generally calls after a dynamic dispatch are dropped from things which build precompile files, and SnoopPrecompile.jl specifically fixes that and I’ve seen that cause dramatic differences. I am curious whether AutoSysimage took the care to handle that (or how it’s building its trace)

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [October 18, 2022, 7:06pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/6 "2022-10-18T19:06:50Z")

</div>

Just as update, the TTFP is now down from 7.4s to 5.5s… Not so sure why, I guess the new version of Plots.jl made the difference, could also be something else…

Allocations also went down a lot:

```julia
asysimg> @time include("src/plot.jl")
To zoom, draw a rectangle while keeping the right mouse key pressed!
To go back to see the full graph, press <CTRL><f>
    5.473786 seconds (14.53 M allocations: 755.695 MiB, 9.02% gc time, 99.41% compilation time)

```

---

<div class="post-metadata">

### Author: ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)
#### Post date: [October 18, 2022, 7:12pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/7 "2022-10-18T19:12:55Z")

</div>

A bit tangential, as it is not the same plotting library, but I am getting something a bit better when using Makie on current Julia master.

With a sysimage that took just a couple of clicks to prepare in vscode:

```julia
julia> @time @eval using CairoMakie
  0.008680 seconds (14.54 k allocations: 927.412 KiB)

julia> @time plot([1,2,3])
  2.082096 seconds (1.94 M allocations: 130.274 MiB, 2.15% gc time, 37.41% compilation time)

```

Without a custom sysimage:

```julia
julia> @time @eval using CairoMakie
 13.082514 seconds (17.49 M allocations: 1.247 GiB, 4.57% gc time, 3.01% compilation time: <1% of which was recompilation)

# don't even bother actually making the first plot, it takes more than 30 seconds

```

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [October 18, 2022, 7:22pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/8 "2022-10-18T19:22:59Z")

</div>

Well, did you include the time to display the plot?  
Like:

```julia
using CairoMakie
@time (p=plot([1,2,3]); display(p))

```

And if I try this in the repl, not even a plot window pops up. ☹

---

<div class="post-metadata">

### Author: ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)
#### Post date: [October 18, 2022, 7:35pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/9 "2022-10-18T19:35:17Z")

</div>

Pardon the lack of clarity, this was in vscode where there is a custom show method that makes a plot show up. Yes, that time was included. With GLMakie instead of CairoMakie you can get an independent OpenGL window. That takes 4 seconds with my sysimage.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [October 18, 2022, 9:31pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/10 "2022-10-18T21:31:54Z")

</div>

Using this code:

```julia
using GLMakie

f = Figure()
ax = Axis(f[1, 1])

x = 0:0.01:100
y = sin.(x)

lines!(ax, x, y)
display(f)

```

I get:

```julia
asysimg> @time include("src/plot.jl")
  3.153288 seconds (2.45 M allocations: 153.219 MiB, 1.13% gc time, 52.23% compilation time)
GLMakie.Screen(...)

```

So 3.2s FTTP for GLMakie + system image vs. 5.5s for InspectDR + Plots + system image…

But without system image InspectDR is much faster…  
And as far as I know you cannot use GLMakie together with Plots…

---

<div class="post-metadata">

### Author: ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)
#### Post date: [October 18, 2022, 10:15pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/11 "2022-10-18T22:15:30Z")

</div>

> [@ufechner7](#):
>
> ```julia
> asysimg> @time include("src/plot.jl")
> 3.153288 seconds (2.45 M allocations: 153.219 MiB, 1.13% gc time, 52.23% compilation time)
> 
> ```

I think nonzero compilation time means you haven’t traced all the compilations to include in your system image, unless the package uses closures that resist compilation.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [October 18, 2022, 10:36pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428/12 "2022-10-18T22:36:28Z")

</div>

Well, I am using AutoSysimages.jl …
