From 0c5ce9deadbccb35c591bb2166a993dec3a98f2a Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Thu, 24 Mar 2022 15:29:54 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=82=20more=20precompile=20for=20dynami?= =?UTF-8?q?c=20functions!=20(#1978)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rik Huijzer Co-authored-by: Rik Huijzer <20724914+rikhuijzer@users.noreply.github.com> --- src/Configuration.jl | 19 ++++++++++--------- src/webserver/Dynamic.jl | 2 ++ src/webserver/MsgPack.jl | 3 ++- src/webserver/WebServer.jl | 2 ++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Configuration.jl b/src/Configuration.jl index 6f152fe978..9cd89bdd22 100644 --- a/src/Configuration.jl +++ b/src/Configuration.jl @@ -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 """ diff --git a/src/webserver/Dynamic.jl b/src/webserver/Dynamic.jl index 86b4927552..9eceee0ee1 100644 --- a/src/webserver/Dynamic.jl +++ b/src/webserver/Dynamic.jl @@ -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 @@ -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. diff --git a/src/webserver/MsgPack.jl b/src/webserver/MsgPack.jl index 7aa3bc35b1..8c1addee66 100644 --- a/src/webserver/MsgPack.jl +++ b/src/webserver/MsgPack.jl @@ -85,4 +85,5 @@ end function unpack(args...) MsgPack.unpack(args...) |> decode_extension_and_addbits -end \ No newline at end of file +end +precompile(unpack, (Vector{UInt8},)) \ No newline at end of file diff --git a/src/webserver/WebServer.jl b/src/webserver/WebServer.jl index e3129e9eb0..d15f9b3a18 100644 --- a/src/webserver/WebServer.jl +++ b/src/webserver/WebServer.jl @@ -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) @@ -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