Skip to content

Commit

Permalink
🧂 more precompile for dynamic functions! (#1978)
Browse files Browse the repository at this point in the history
Co-authored-by: Rik Huijzer <rikhuijzer@pm.me>
Co-authored-by: Rik Huijzer <20724914+rikhuijzer@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 24, 2022
1 parent 05a0e05 commit 0c5ce9d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ using Configurations # https://github.com/Roger-luo/Configurations.jl

import ..Pluto: tamepath

# This can't be a simple `const` because this would hard-code it into the precompile image.
const notebook_path_suggestion_ref = Ref{Union{Nothing,String}}(nothing)
# 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}}()
function notebook_path_suggestion()
if notebook_path_suggestion_ref[] === nothing
notebook_path_suggestion_ref[] = let
preferred_dir = startswith(Sys.BINDIR, pwd()) ? homedir() : pwd()
joinpath(preferred_dir, "") # so that it ends with / or \
end
end
notebook_path_suggestion_ref[]
pwd_val = something(pwd_ref[], pwd())
preferred_dir = startswith(Sys.BINDIR, pwd_val) ? homedir() : pwd_val
# so that it ends with / or \
string(joinpath(preferred_dir, ""))
end

function __init__()
pwd_ref[] = pwd()
end

"""
Expand Down
2 changes: 2 additions & 0 deletions src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ end
# All of the arrays in the notebook_to_js object are 'immutable' (we write code as if they are), so we can enable this optimization:
Firebasey.use_triple_equals_for_arrays[] = true


# the only possible Arrays are:
# - cell_order
# - cell_execution_order
Expand Down Expand Up @@ -169,6 +170,7 @@ function notebook_to_js(notebook::Notebook)
"cell_execution_order" => cell_id.(collect(topological_order(notebook))),
)
end
precompile(notebook_to_js, (Notebook,))

"""
For each connected client, we keep a copy of their current state. This way we know exactly which updates to send when the server-side state changes.
Expand Down
3 changes: 2 additions & 1 deletion src/webserver/MsgPack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ end

function unpack(args...)
MsgPack.unpack(args...) |> decode_extension_and_addbits
end
end
precompile(unpack, (Vector{UInt8},))
2 changes: 2 additions & 0 deletions src/webserver/WebServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function run(; kwargs...)
options = Configuration.from_flat_kwargs(; kwargs...)
run(options)
end
precompile(run, ())

function run(options::Configuration.Options)
session = ServerSession(; options)
Expand Down Expand Up @@ -323,6 +324,7 @@ function run(session::ServerSession, pluto_router)
end
end
end
precompile(run, (ServerSession, HTTP.Handlers.Router{Symbol("##001")}))

get_favorite_notebook(notebook:: Nothing) = nothing
get_favorite_notebook(notebook:: String) = notebook
Expand Down

0 comments on commit 0c5ce9d

Please sign in to comment.