Skip to content

Commit 4c4e078

Browse files
committed
Add precompiles to reduce time to first Revise.revise()
Perhaps the most annoying thing about Revise now is that the first revision is quite slow, about 3.1s on my machine. This PR drops the time to about 2.4s. Basically the idea is to precompile statements that Revise will need. Discovered via the new snoopi_deep/Core.Compiler.Timings framework.
1 parent 99402b4 commit 4c4e078

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

contrib/generate_precompile.jl

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ UP_ARROW = "\e[A"
1515
DOWN_ARROW = "\e[B"
1616

1717
hardcoded_precompile_statements = """
18-
# used by JuliaInterpreter.jl and Revise.jl
18+
# used by Revise.jl
1919
@assert precompile(Tuple{typeof(Base.parse_cache_header), String})
20-
@assert precompile(Tuple{typeof(pushfirst!), Vector{Any}, Function})
21-
@assert precompile(Tuple{typeof(push!), Set{Module}, Module})
22-
@assert precompile(Tuple{typeof(push!), Set{Method}, Method})
23-
@assert precompile(Tuple{typeof(empty!), Set{Any}})
20+
@assert precompile(Base.read_dependency_src, (String, String))
21+
@assert precompile(Base.CoreLogging.current_logger_for_env, (Base.CoreLogging.LogLevel, String, Module))
22+
2423
# used by Requires.jl
2524
@assert precompile(Tuple{typeof(get!), Type{Vector{Function}}, Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
2625
@assert precompile(Tuple{typeof(haskey), Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
@@ -56,10 +55,34 @@ cd("complet_path\t\t$CTRL_C
5655
"""
5756

5857
precompile_script = """
59-
# Used by Revise
58+
# Used by Revise & its dependencies
59+
delete!(push!(Set{Module}(), Base), Main)
60+
m = first(methods(+))
61+
delete!(push!(Set{Method}(), m), m)
62+
empty!(Set())
63+
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
6064
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
65+
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
6166
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
67+
(setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
68+
(setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
69+
Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
70+
Dict(Base => [:(1+1)])[Base]
71+
Dict(:one => [1])[:one]
72+
Dict("abc" => Set())["abc"]
73+
pushfirst!([], sum)
6274
get(Base.pkgorigins, Base.PkgId(Base), nothing)
75+
sort!([1,2,3])
76+
unique!([1,2,3])
77+
cumsum([1,2,3])
78+
append!(Int[], BitSet())
79+
isempty(BitSet())
80+
delete!(BitSet([1,2]), 3)
81+
deleteat!(Int32[1,2,3], [1,3])
82+
deleteat!(Any[1,2,3], [1,3])
83+
Core.svec(1, 2) == Core.svec(3, 4)
84+
copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(which(+, (Int, Int)), [Int, Int], Core.svec())))
85+
any(t->t[1].line > 1, [(LineNumberNode(2,:none),:(1+1))])
6386
"""
6487

6588
julia_exepath() = joinpath(Sys.BINDIR::String, Base.julia_exename())
@@ -72,21 +95,26 @@ if have_repl
7295
"""
7396
end
7497

75-
# This is disabled because it doesn't give much benefit
76-
# and the code in Distributed is poorly typed causing many invalidations
77-
#=
7898
Distributed = get(Base.loaded_modules,
7999
Base.PkgId(Base.UUID("8ba89e20-285c-5b6f-9357-94700520ee1b"), "Distributed"),
80100
nothing)
81101
if Distributed !== nothing
102+
hardcoded_precompile_statements *= """
103+
@assert precompile(Tuple{typeof(Distributed.remotecall),Function,Int,Module,Vararg{Any, 100}})
104+
@assert precompile(Tuple{typeof(Distributed.procs)})
105+
@assert precompile(Tuple{typeof(Distributed.finalize_ref), Distributed.Future})
106+
"""
107+
# This is disabled because it doesn't give much benefit
108+
# and the code in Distributed is poorly typed causing many invalidations
109+
#=
82110
precompile_script *= """
83111
using Distributed
84112
addprocs(2)
85113
pmap(x->iseven(x) ? 1 : 0, 1:4)
86114
@distributed (+) for i = 1:100 Int(rand(Bool)) end
87115
"""
88-
end
89116
=#
117+
end
90118

91119

92120
Artifacts = get(Base.loaded_modules,
@@ -121,6 +149,7 @@ if FileWatching !== nothing
121149
hardcoded_precompile_statements *= """
122150
@assert precompile(Tuple{typeof(FileWatching.watch_file), String, Float64})
123151
@assert precompile(Tuple{typeof(FileWatching.watch_file), String, Int})
152+
@assert precompile(Tuple{typeof(FileWatching._uv_hook_close), FileWatching.FileMonitor})
124153
"""
125154
end
126155

0 commit comments

Comments
 (0)