# Pluto notebook is slower than REPL

**URL:** <https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145>\
**Category:** General Usage\
**Tags:** pluto\
**Created:** [March 19, 2025, 4:02pm UTC](https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145 "2025-03-19T16:02:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![contejuz](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@contejuz](https://discourse.julialang.org/u/contejuz)\
**Post date:** [March 19, 2025, 4:02pm UTC](https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145/1 "2025-03-19T16:02:15Z")

</div>

Is there any reason a Pluto notebook can be slower than the REPL? When I use @time, it seems like both take the same amount of time to run a particular function (involving sampling from a probabilistic program using Gen.jl and plotting using WGLMakie). However, the plot takes about 1 second longer to update on Pluto. This becomes worse for longer simulations. I’m not sure if this is an issue with WGLMakie or with Pluto using more memory.

---

<div class="post-metadata">

**Author:** ![savq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/savq/32/22063_2.png) [@savq](https://discourse.julialang.org/u/savq)\
**Post date:** [March 19, 2025, 10:15pm UTC](https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145/2 "2025-03-19T22:15:26Z")

</div>

Pluto does a little extra work compared to the REPL, like checking dependencies between cells. However, 1 second seems like a lot.

Without knowing more about your specific problem, I’ll throw the generic recommendation of avoiding having too much global state. Prefer `function` over `let`, and prefer `let` over `begin`.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [March 19, 2025, 10:29pm UTC](https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145/3 "2025-03-19T22:29:17Z")

</div>

A minimal working example that reproduces the behaviour would be nice!

---

<div class="post-metadata">

**Author:** ![contejuz](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@contejuz](https://discourse.julialang.org/u/contejuz)\
**Post date:** [March 20, 2025, 2:57pm UTC](https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145/4 "2025-03-20T14:57:18Z")

</div>

Sorry, I should have provided that in my original post.

```julia
using Gen, GLMakie, Statistics

@gen function line_model(xs::Vector{Float64})
    slope = ({:slope} ~ normal(0, 1))
    intercept = ({:intercept} ~ normal(0, 2))
    function y(x)
        return slope * x + intercept
    end
    for (i, x) in enumerate(xs)
        ({(:y, i)} ~ normal(y(x), 0.5))
    end
    return y
end;

xs=collect(-5.0:0.5:5.0)

function plot_trace(trace,ax)
    xs=Gen.get_args(trace)[1]
    y=Gen.get_retval(trace)
    y_i=[trace[(:y, i)] for i in 1:length(xs)]
    dom=collect(xs[1]:0.1:xs[end])
    lines!(ax,dom,y.(dom),color="black")
    scatter!(ax,xs,y_i)
end

function sample_models(model,xs)
    fig=Figure()
    ax=[Axis(fig[i,j]) for j in 1:5 for i in 1:5]
    for i in 1:25
        trace = Gen.simulate(model, (xs,))
        plot_trace(trace,ax[i])
    end
    [xlims!(ax[i],-5,5) for i in 1:25]
    [ylims!(ax[i],-5,5) for i in 1:25]
    display(fig)
end

@time sample_models(line_model,xs)

```

I run the same code through the REPL and in a Pluto notebook. On Pluto, each block is split into a separate cell. Usually I would use GLMakie on my REPL, but Pluto seems to have trouble updating plots using GLMakie (I have to redisplay the figure) so I’m using WGLMakie for both for a fair comparison since afaik WGLMakie is slower than GLMakie.

After the first run (which takes extra time for JIT), I average about 0.75 seconds on my REPL. WGLMakie updates as soon as `sample_models` returns the figure. Note that I’m regenerating the figure each time rather than emptying the axes and replotting. I’m doing so because typically I want to run simulations with different inputs and plot separate figures.

On Pluto, `@time` says 0.1 seconds, but the plot takes longer to update, seemingly longer than on the REPL. The discrepancy seems to be more apparent when the memory usage of the notebook is higher. Is the difference in the output of `@time` just a result of how Pluto is implemented?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [March 20, 2025, 3:06pm UTC](https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145/5 "2025-03-20T15:06:25Z")

</div>

Pluto certainly has an overhead.  
Are you animating this by calling display again?  
That seems like it should be a lot slower, and could potentially be even slower in Pluto.  
If the plots are too complex to use observables/mutation, you could take a look at the SpecApi, which allows you to define whole figures as an observable that you can update on new data:

> **[SpecApi | Makie](https://docs.makie.org/stable/explanations/specapi#Interactive-example)**
>
> Create impressive data visualizations with Makie, the plotting ecosystem for the Julia language. Build aesthetic plots with beautiful customizable themes, control every last detail of publication quality vector graphics, assemble complex layouts and...

---

<div class="post-metadata">

**Author:** ![contejuz](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@contejuz](https://discourse.julialang.org/u/contejuz)\
**Post date:** [March 22, 2025, 1:34am UTC](https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145/6 "2025-03-22T01:34:07Z")

</div>

I don’t explicitly call display but I do return the figure so that it displays when I run the function.

Thanks, I’ll look into SpecApi!

---

<div class="post-metadata">

**Author:** ![contejuz](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@contejuz](https://discourse.julialang.org/u/contejuz)\
**Post date:** [March 22, 2025, 2:43am UTC](https://discourse.julialang.org/t/pluto-notebook-is-slower-than-repl/127145/7 "2025-03-22T02:43:32Z")

</div>

Thanks. From the sidebar progress breakdown, it seems like the dependency check overhead is not high. However, I notice that the timer for each plot cell runs for longer than the final time that it shows. So it seems like there is some other process running before the cell completes that Pluto isn’t tracking timewise.
