Skip to content

Commit

Permalink
Tweak precompiles for reduced Requires/Revise latency (#37574)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Sep 16, 2020
1 parent 3028ade commit 8c07013
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions base/experimental.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ Closest candidates are:
To insulate yourself against changes, consider putting any registrations inside an
`if isdefined(Base.Experimental, :register_error_hint) ... end` block.
"""
function register_error_hint(handler, exct::Type)
list = get!(()->[], _hint_handlers, exct)
function register_error_hint(@nospecialize(handler), @nospecialize(exct::Type))
list = get!(Vector{Any}, _hint_handlers, exct)
push!(list, handler)
return nothing
end
Expand Down
34 changes: 26 additions & 8 deletions contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ UP_ARROW = "\e[A"
DOWN_ARROW = "\e[B"

hardcoded_precompile_statements = """
@assert precompile(Tuple{typeof(Base.stale_cachefile), String, String})
@assert precompile(Tuple{typeof(push!), Set{Module}, Module})
@assert precompile(Tuple{typeof(push!), Set{Method}, Method})
@assert precompile(Tuple{typeof(push!), Set{Base.PkgId}, Base.PkgId})
@assert precompile(Tuple{typeof(getindex), Dict{Base.PkgId,String}, Base.PkgId})
@assert precompile(Tuple{typeof(setindex!), Dict{String,Base.PkgId}, Base.PkgId, String})
# used by Revise.jl
@assert precompile(Tuple{typeof(Base.parse_cache_header), String})
@assert precompile(Tuple{typeof(pushfirst!), Vector{Any}, Function})
# used by Requires.jl
@assert precompile(Tuple{typeof(get!), Type{Vector{Function}}, Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
@assert precompile(Tuple{typeof(haskey), Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
@assert precompile(Tuple{typeof(delete!), Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
@assert precompile(Tuple{typeof(push!), Vector{Function}, Function})
# miscellaneous
@assert precompile(Tuple{typeof(Base.require), Base.PkgId})
@assert precompile(Tuple{typeof(isassigned), Core.SimpleVector, Int})
@assert precompile(Tuple{typeof(pushfirst!), Vector{Any}, Function})
@assert precompile(Tuple{typeof(Base.parse_cache_header), String})
@assert precompile(Tuple{typeof(Base.Experimental.register_error_hint), Any, Type})
"""

precompile_script = """
Expand All @@ -43,6 +45,13 @@ f(x) = x03
f(1,2)
[][1]
cd("complet_path\t\t$CTRL_C
# Used by JuliaInterpreter
push!(Set{Module}(), Main)
push!(Set{Method}(), first(methods(collect)))
# Used by Revise
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
get(Base.pkgorigins, Base.PkgId(Base), nothing)
"""

julia_exepath() = joinpath(Sys.BINDIR, Base.julia_exename())
Expand Down Expand Up @@ -100,6 +109,15 @@ if FileWatching !== nothing
"""
end

Libdl = get(Base.loaded_modules,
Base.PkgId(Base.UUID("8f399da3-3557-5675-b5ff-fb832c97cbdb"), "Libdl"),
nothing)
if Libdl !== nothing
hardcoded_precompile_statements *= """
precompile(Tuple{typeof(Libc.Libdl.dlopen), String})
"""
end

function generate_precompile_statements()
start_time = time_ns()
debug_output = devnull # or stdout
Expand Down

0 comments on commit 8c07013

Please sign in to comment.