Skip to content

Commit

Permalink
Use SnoopPrecompile (#2441)
Browse files Browse the repository at this point in the history
Co-authored-by: Fons van der Plas <[email protected]>
  • Loading branch information
rikhuijzer and fonsp authored Jan 20, 2023
1 parent 9f560b1 commit 61951fa
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/FrontendTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
jobs:
frontend-test:
runs-on: "ubuntu-latest"
timeout-minutes: 30

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 40

strategy:
# Without setting this, a failing test cancels all others
fail-fast: false
Expand All @@ -41,7 +41,7 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Makes thes `julia` command available
# Makes the `julia` command available
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ frontend/dist
.net
net
frontend/package-lock.json

# PProf
profile.pb.gz
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ PrecompileSignatures = "91cefc8d-f054-46dc-8f8c-26e11d7c5411"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
RegistryInstances = "2792f1a3-b283-48e8-9a74-f99dce5104f3"
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Expand All @@ -39,6 +40,7 @@ MsgPack = "1.1"
PrecompileSignatures = "3"
RegistryInstances = "0.1"
RelocatableFolders = "0.1, 0.2, 0.3, 1"
SnoopPrecompile = "1"
Tables = "1"
URIs = "1.3"
julia = "^1.6"
Expand Down
8 changes: 6 additions & 2 deletions src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ catch e
end

# Using a ref to avoid fixing the pwd() output during the compilation phase. We don't want this value to be baked into the sysimage, because it depends on the `pwd()`. We do want to cache it, because the pwd might change while Pluto is running.
const pwd_ref = Ref{Union{Nothing,String}}()
const pwd_ref = Ref{String}()
function notebook_path_suggestion()
pwd_val = something(pwd_ref[], safepwd())
pwd_val = if isassigned(pwd_ref)
pwd_ref[]
else
safepwd()
end
preferred_dir = startswith(Sys.BINDIR, pwd_val) ? homedir() : pwd_val
# so that it ends with / or \
string(joinpath(preferred_dir, ""))
Expand Down
7 changes: 2 additions & 5 deletions src/Pluto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export reset_notebook_environment
export update_notebook_environment
export activate_notebook_environment

include("./precompile.jl")

if get(ENV, "JULIA_PLUTO_SHOW_BANNER", "1") != "0" && get(ENV, "CI", "🍄") != "true"
@info """\n
Welcome to Pluto $(PLUTO_VERSION_STR) 🎈
Expand All @@ -106,9 +108,4 @@ if get(ENV, "JULIA_PLUTO_SHOW_BANNER", "1") != "0" && get(ENV, "CI", "🍄") !=
\n"""
end

# Generate and include `precompile` directives during the precompilation phase.
# This aims to reduce the time to first X (time to first running notebook in this case).
using PrecompileSignatures: @precompile_signatures
@precompile_signatures(Pluto)

end
81 changes: 81 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using SnoopPrecompile: SnoopPrecompile

const __TEST_NOTEBOOK_ID = uuid1()

SnoopPrecompile.@precompile_all_calls begin
let
channel = Channel{Any}(10)
Pluto.PlutoRunner.setup_plutologger(
__TEST_NOTEBOOK_ID,
channel,
)
end
expr = Expr(:toplevel, :(1 + 1))
Pluto.PlutoRunner.run_expression(Module(), expr, __TEST_NOTEBOOK_ID, uuid1(), nothing);

nb = Pluto.Notebook([
Pluto.Cell("""md"Hello *world*" """)
Pluto.Cell("""[f(x)]""")
Pluto.Cell("""x = 1""")
Pluto.Cell(
"""
function f(z::Integer)
z / 123
end
""")
Pluto.Cell(
"""
"asdf"
begin
while false
local p = 123
try
[(x,a...) for x in (a for a in b)]
A.B.hello() do z
@gensym z
(z) -> z/:(z / z)
end
catch
end
end
end
"""
)
])
let
topology = Pluto.updated_topology(nb.topology, nb, nb.cells)
# Our reactive sorting algorithm.
Pluto.topological_order(topology, topology.cell_order)
end

let
io = IOBuffer()
# Notebook file format.
Pluto.save_notebook(io, nb)
seekstart(io)
Pluto.load_notebook_nobackup(io, "whatever.jl")
end

let
state1 = Pluto.notebook_to_js(nb)
state2 = Pluto.notebook_to_js(nb)
# MsgPack
Pluto.unpack(Pluto.pack(state1))
# State diffing
Pluto.Firebasey.diff(state1, state2)
end

s = Pluto.ServerSession(;
options=Pluto.Configuration.from_flat_kwargs(
disable_writing_notebook_files=true,
workspace_use_distributed=false,
auto_reload_from_file=false,
run_notebook_on_load=false,
lazy_workspace_creation=true,
capture_stdout=false,
)
)
end

using PrecompileSignatures: @precompile_signatures
@precompile_signatures(Pluto)

0 comments on commit 61951fa

Please sign in to comment.