Skip to content

Commit a36c825

Browse files
authored
Precompile watch_file and a few other functions used by Revise (#37403)
Together with some internal changes coming in Revise v3.0, on my machine this drops the overhead of `using Revise` from 3.5s to 0.5s. This change only contributes about 0.1s of that time, but out of 0.5s it's a noticeable improvement. The only one of these that makes a sizable impact is `watch_file`, but this does ensure that Revise doesn't trigger any additional "generic" compilation.
1 parent c0b6afb commit a36c825

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

contrib/generate_precompile.jl

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

1717
hardcoded_precompile_statements = """
18-
precompile(Tuple{typeof(Base.stale_cachefile), String, String})
19-
precompile(Tuple{typeof(push!), Set{Module}, Module})
20-
precompile(Tuple{typeof(push!), Set{Method}, Method})
21-
precompile(Tuple{typeof(push!), Set{Base.PkgId}, Base.PkgId})
22-
precompile(Tuple{typeof(setindex!), Dict{String,Base.PkgId}, Base.PkgId, String})
23-
precompile(Tuple{typeof(get!), Type{Vector{Function}}, Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
18+
@assert precompile(Tuple{typeof(Base.stale_cachefile), String, String})
19+
@assert precompile(Tuple{typeof(push!), Set{Module}, Module})
20+
@assert precompile(Tuple{typeof(push!), Set{Method}, Method})
21+
@assert precompile(Tuple{typeof(push!), Set{Base.PkgId}, Base.PkgId})
22+
@assert precompile(Tuple{typeof(setindex!), Dict{String,Base.PkgId}, Base.PkgId, String})
23+
@assert precompile(Tuple{typeof(get!), Type{Vector{Function}}, Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
24+
@assert precompile(Tuple{typeof(isassigned), Core.SimpleVector, Int})
25+
@assert precompile(Tuple{typeof(pushfirst!), Vector{Any}, Function})
2426
"""
2527

2628
precompile_script = """
@@ -45,6 +47,11 @@ julia_exepath() = joinpath(Sys.BINDIR, Base.julia_exename())
4547

4648
have_repl = haskey(Base.loaded_modules,
4749
Base.PkgId(Base.UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL"))
50+
if have_repl
51+
hardcoded_precompile_statements *= """
52+
@assert precompile(Tuple{typeof(getproperty), REPL.REPLBackend, Symbol})
53+
"""
54+
end
4855

4956
Distributed = get(Base.loaded_modules,
5057
Base.PkgId(Base.UUID("8ba89e20-285c-5b6f-9357-94700520ee1b"), "Distributed"),
@@ -66,6 +73,16 @@ if Pkg !== nothing
6673
precompile_script *= Pkg.precompile_script
6774
end
6875

76+
FileWatching = get(Base.loaded_modules,
77+
Base.PkgId(Base.UUID("7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"), "FileWatching"),
78+
nothing)
79+
if FileWatching !== nothing
80+
hardcoded_precompile_statements *= """
81+
@assert precompile(Tuple{typeof(FileWatching.watch_file), String, Float64})
82+
@assert precompile(Tuple{typeof(FileWatching.watch_file), String, Int})
83+
"""
84+
end
85+
6986
function generate_precompile_statements()
7087
start_time = time_ns()
7188
debug_output = devnull # or stdout

stdlib/FileWatching/src/FileWatching.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ giving the result of watching the file.
688688
This behavior of this function varies slightly across platforms. See
689689
<https://nodejs.org/api/fs.html#fs_caveats> for more detailed information.
690690
"""
691-
function watch_file(s::AbstractString, timeout_s::Real=-1)
691+
function watch_file(s::String, timeout_s::Float64=-1.0)
692692
fm = FileMonitor(s)
693693
local timer
694694
try
@@ -703,6 +703,7 @@ function watch_file(s::AbstractString, timeout_s::Real=-1)
703703
@isdefined(timer) && close(timer)
704704
end
705705
end
706+
watch_file(s::AbstractString, timeout_s::Real=-1) = watch_file(String(s), Float64(timeout_s))
706707

707708
"""
708709
watch_folder(path::AbstractString, timeout_s::Real=-1)

0 commit comments

Comments
 (0)