Pluto.jl icon indicating copy to clipboard operation
Pluto.jl copied to clipboard

Import PlutoRunner as module in Loader.jl

Open dralletje opened this issue 2 years ago • 9 comments

No idea if this is faster currently, or if it will every be... But apart from having to do Pkg.develop() this feels like a more mature way to load PlutoRunner :P

dralletje avatar Feb 02 '22 01:02 dralletje

Try this Pull Request!

Open Julia and type:

julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/fonsp/Pluto.jl", rev="PlutoRunner-as-module")
julia> using Pluto

github-actions[bot] avatar Feb 02 '22 01:02 github-actions[bot]

Nice! I ended up rewriting the whole thing:

  • Now using LOAD_PATH and Base.ACTIVE_PROJECT instead of pkg_ctx (this fixed the tests)
  • NotebookBootEnvironment.toml no longer needed, since PlutoRunner is the only "dependency"
  • Bit cleaner with try ... finally

fonsp avatar Feb 02 '22 20:02 fonsp

We still need to test:

  • [ ] Does this improve launch time? (@rikhuijzer can you use the new benchmark system to test this?) EDIT: looks like there is almost no difference...
  • [x] How do different Pluto versions interfere? (@fonsp will do this) EDIT: works just like before
  • [x] What about RelocatableFolders.jl? (Was that working before?) EDIT: very likely that it will work

fonsp avatar Feb 02 '22 20:02 fonsp

Nice! I ended up rewriting the whole thing:

  • Now using LOAD_PATH and Base.ACTIVE_PROJECT instead of pkg_ctx

  • NotebookBootEnvironment.toml no longer needed, since PlutoRunner is the only "dependency"

  • Bit cleaner with try ... finally

Eyeroll... 😉

dralletje avatar Feb 02 '22 20:02 dralletje

  • [ ] What about RelocatableFolders.jl? (Was that working before?)

I'll test it, but I'm pretty sure that still works as RelocatableFolders will "just" create the whole runner folder.

dralletje avatar Feb 02 '22 20:02 dralletje

Does this improve launch time? (@rikhuijzer can you use the new benchmark system to test this?)

Hard to tell since this branch isn't up-to-date with main. I've manually added the compile tests on top of this branch and it doesn't look off. Some stuff of the PlutoRunner is covered via SessionActions.open. I should definitely add some PlutoRunner benchmarks.

rikhuijzer avatar Mar 18 '22 15:03 rikhuijzer

Let me rebase! Sorry about that

fonsp avatar Mar 18 '22 16:03 fonsp

Updated! The main benefit should be in the launch time of the second notebook, because PlutoRunner can be precompiled like a package.

Op 18 mrt. 2022, om 16:37 heeft Rik Huijzer @.***> het volgende geschreven:

Does this improve launch time? @.*** https://github.com/rikhuijzer can you use the new benchmark system to test this?)

Hard to tell since this branch isn't up-to-date with main. I've manually added the compile tests on top of this branch and it doesn't look off. Some stuff of the PlutoRunner is covered via SessionActions.open. I should definitely some PlutoRunner benchmarks.

Don't let performance nitpicks come in the way of features :) We can always optimize later.

— Reply to this email directly, view it on GitHub https://github.com/fonsp/Pluto.jl/pull/1881#issuecomment-1072529301, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABU4YBUMV2EQLMYIZ2TZJ3DVASPNLANCNFSM5NKYHFFA. You are receiving this because you were mentioned.

fonsp avatar Mar 18 '22 23:03 fonsp

This PR can cause problems when you use Pluto inside Pluto, at a different version than the server. But that problem might already be there because we check the existence of Main.PlutoRunner... needs more thinking

EDIT: this might only be an issue when not using distributed computing, but that might already be a problem before this PR.

fonsp avatar Apr 20 '22 11:04 fonsp

With 1.9 it might be interesting to revisit this PR. Here are some unscientific measurements:

On main (julia 1.9-rc2):

julia> @time let
           nb = Pluto.Notebook([Pluto.Cell("1 + 1")])
           sess = Pluto.ServerSession()
           Pluto.update_run!(sess, nb, nb.cells)
           nb.cells[1].output.body
       end
  7.291519 seconds (164.88 k allocations: 12.471 MiB, 0.29% compilation time)
"2"

With the loader as a package, this pr (julia 1.9-rc2):

julia> @time let
           nb = Pluto.Notebook([Pluto.Cell("1 + 1")])
           sess = Pluto.ServerSession()
           Pluto.update_run!(sess, nb, nb.cells)
           nb.cells[1].output.body
       end
  5.720203 seconds (164.12 k allocations: 12.435 MiB, 0.36% compilation time)
"2"

Note that there are no precompile statements in PlutoRunner itself so it can probably be improved more?

This PR can cause problems when you use Pluto inside Pluto, at a different version than the server. But that problem might already be there because we check the existence of Main.PlutoRunner... needs more thinking

This problem will be solved when we enable Malt so that each Pluto instance can drive its own notebook processes independently.

Pangoraw avatar Apr 14 '23 11:04 Pangoraw

I'd like to add that apart from precompilation time this PR (making PlutoRunner its own package with UUID) will open up a lot of possibilities regarding building package extensions to do Pluto specific stuff.

At the moment one has to rely on AbstractPlutoDingetjes but having a Pluto-functionality extensions for packages that are loaded when PlutoRunner is loaded (so inside Pluto) would be super nice!

disberd avatar Aug 23 '23 10:08 disberd

Woohooo almost ready!

We thought hard about interference between Pluto versions and nested Pluto and it will be fine!

TODO:

  • Wait for CI
  • Rerun benchmark from Paul's previous commet

fonsp avatar Dec 02 '23 14:12 fonsp

Benchmark results

On main (b15d420)

julia> import Pluto
       @time let
           nb = Pluto.Notebook([Pluto.Cell("1 + 1")])
           sess = Pluto.ServerSession()
           Pluto.update_run!(sess, nb, nb.cells)
           nb.cells[1].output.body
       end
8.171571 seconds (190.23 k allocations: 14.144 MiB, 0.54% compilation time)
"2"

This PR

julia> import Pluto
       @time let
           nb = Pluto.Notebook([Pluto.Cell("1 + 1")])
           sess = Pluto.ServerSession()
           Pluto.update_run!(sess, nb, nb.cells)
           nb.cells[1].output.body
       end
6.713073 seconds (178.20 k allocations: 13.227 MiB, 0.33% compilation time)
"2"

Pangoraw avatar Dec 03 '23 17:12 Pangoraw

lets merge!

fonsp avatar Dec 04 '23 10:12 fonsp

On Julia 1.9, launching the second notebook in a session with Malt went from 4 seconds to 3 seconds :)

fonsp avatar Dec 06 '23 15:12 fonsp