Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate precompile directives via PrecompileSignatures.jl #2054

Merged
merged 12 commits into from
May 2, 2022
2 changes: 1 addition & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/cache@v1

# 🚗
- uses: julia-actions/julia-runtest@v1
continue-on-error: ${{ matrix.julia-version == 'nightly' }}
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MIMEs = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
MsgPack = "99f44e22-a591-53d1-9472-aa23ef4bd671"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrecompileSignatures = "91cefc8d-f054-46dc-8f8c-26e11d7c5411"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Expand All @@ -27,10 +28,11 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Configurations = "0.15, 0.16, 0.17"
FuzzyCompletions = "0.3,0.4,0.5"
FuzzyCompletions = "0.3, 0.4, 0.5"
HTTP = "^0.9.1"
MIMEs = "0.1"
MsgPack = "1.1"
PrecompileSignatures = "3"
RelocatableFolders = "0.1, 0.2"
Tables = "1"
julia = "^1.6"
Expand Down
6 changes: 6 additions & 0 deletions src/Pluto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_m
@eval Base.Experimental.@max_methods 1
end

import FuzzyCompletions
import RelocatableFolders: @path
const ROOT_DIR = normpath(joinpath(@__DIR__, ".."))
const FRONTEND_DIR = @path(joinpath(ROOT_DIR, "frontend"))
Expand Down Expand Up @@ -101,4 +102,9 @@ 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
1 change: 0 additions & 1 deletion src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ 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
4 changes: 0 additions & 4 deletions src/webserver/SessionActions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function open(session::ServerSession, path::AbstractString; run_async=true, comp
try_event_call(session, OpenNotebookEvent(nb))
nb
end
precompile(open, (ServerSession, String))

function add(session::ServerSession, nb::Notebook; run_async::Bool=true)
session.notebooks[nb.notebook_id] = nb
Expand Down Expand Up @@ -161,7 +160,6 @@ function add(session::ServerSession, nb::Notebook; run_async::Bool=true)

nb
end
precompile(add, (ServerSession, Notebook))

"""
Generate a non-existing new notebook filename, and write `contents` to that file. Return the generated filename.
Expand Down Expand Up @@ -230,7 +228,6 @@ function new(session::ServerSession; run_async=true, notebook_id::UUID=uuid1())
try_event_call(session, OpenNotebookEvent(nb))
nb
end
precompile(new, (ServerSession,))

"Shut down `notebook` inside `session`. If `keep_in_session` is `false` (default), you will not be allowed to run a notebook with the same notebook_id again."
function shutdown(session::ServerSession, notebook::Notebook; keep_in_session::Bool=false, async::Bool=false, verbose::Bool=true)
Expand All @@ -252,6 +249,5 @@ function shutdown(session::ServerSession, notebook::Notebook; keep_in_session::B
WorkspaceManager.unmake_workspace((session, notebook); async, verbose, allow_restart=keep_in_session)
try_event_call(session, ShutdownNotebookEvent(notebook))
end
precompile(shutdown, (ServerSession, Notebook))

end
1 change: 0 additions & 1 deletion src/webserver/WebServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function run(; kwargs...)
options = Configuration.from_flat_kwargs(; kwargs...)
run(options)
end
precompile(run, ())

function run(options::Configuration.Options)
session = ServerSession(; options)
Expand Down
7 changes: 7 additions & 0 deletions test/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
using TimerOutputs: TimerOutput, @timeit
const TOUT = TimerOutput()
macro timeit_include(path::AbstractString) :(@timeit TOUT $path include($path)) end
function print_timeroutput()
# Sleep to avoid old logs getting tangled up in the output.
sleep(6)
println()
show(TOUT; compact=true, sortby=:firstexec)
println()
end

@timeit TOUT "import Pluto" import Pluto
import Pluto.ExpressionExplorer
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include("helpers.jl")
@timeit_include("compiletimes.jl")
verify_no_running_processes()
if get(ENV, "PLUTO_TEST_ONLY_COMPILETIMES", nothing) == "true"
show(TOUT; compact=true, sortby=:firstexec)
print_timeroutput()
exit(0)
end
@timeit_include("Events.jl")
Expand Down Expand Up @@ -49,7 +49,7 @@ verify_no_running_processes()

verify_no_running_processes()

show(TOUT; compact=true, sortby=:firstexec)
print_timeroutput()

# TODO: test PlutoRunner functions like:
# - from_this_notebook
Expand Down