Skip to content

Commit 26b3b5f

Browse files
move precompile workload back from Base (#53679)
1 parent ccdf89e commit 26b3b5f

File tree

2 files changed

+52
-87
lines changed

2 files changed

+52
-87
lines changed

base/Base.jl

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -568,61 +568,6 @@ end_base_include = time_ns()
568568
const _sysimage_modules = PkgId[]
569569
in_sysimage(pkgid::PkgId) = pkgid in _sysimage_modules
570570

571-
# Precompiles for Revise and other packages
572-
# TODO: move these to contrib/generate_precompile.jl
573-
# The problem is they don't work there
574-
for match = _methods(+, (Int, Int), -1, get_world_counter())
575-
m = match.method
576-
delete!(push!(Set{Method}(), m), m)
577-
copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(match), typemax(UInt)))
578-
579-
empty!(Set())
580-
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
581-
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
582-
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
583-
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
584-
(setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
585-
(setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
586-
Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
587-
Dict(Base => [:(1+1)])[Base]
588-
Dict(:one => [1])[:one]
589-
Dict("abc" => Set())["abc"]
590-
pushfirst!([], sum)
591-
get(Base.pkgorigins, Base.PkgId(Base), nothing)
592-
sort!([1,2,3])
593-
unique!([1,2,3])
594-
cumsum([1,2,3])
595-
append!(Int[], BitSet())
596-
isempty(BitSet())
597-
delete!(BitSet([1,2]), 3)
598-
deleteat!(Int32[1,2,3], [1,3])
599-
deleteat!(Any[1,2,3], [1,3])
600-
Core.svec(1, 2) == Core.svec(3, 4)
601-
any(t->t[1].line > 1, [(LineNumberNode(2,:none), :(1+1))])
602-
603-
# Code loading uses this
604-
sortperm(mtime.(readdir(".")), rev=true)
605-
# JLLWrappers uses these
606-
Dict{UUID,Set{String}}()[UUID("692b3bcd-3c85-4b1f-b108-f13ce0eb3210")] = Set{String}()
607-
get!(Set{String}, Dict{UUID,Set{String}}(), UUID("692b3bcd-3c85-4b1f-b108-f13ce0eb3210"))
608-
eachindex(IndexLinear(), Expr[])
609-
push!(Expr[], Expr(:return, false))
610-
vcat(String[], String[])
611-
k, v = (:hello => nothing)
612-
precompile(indexed_iterate, (Pair{Symbol, Union{Nothing, String}}, Int))
613-
precompile(indexed_iterate, (Pair{Symbol, Union{Nothing, String}}, Int, Int))
614-
# Preferences uses these
615-
precompile(get_preferences, (UUID,))
616-
precompile(record_compiletime_preference, (UUID, String))
617-
get(Dict{String,Any}(), "missing", nothing)
618-
delete!(Dict{String,Any}(), "missing")
619-
for (k, v) in Dict{String,Any}()
620-
println(k)
621-
end
622-
623-
break # only actually need to do this once
624-
end
625-
626571
if is_primary_base_module
627572

628573
# Profiling helper

contrib/generate_precompile.jl

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,59 @@ for T in (Float16, Float32, Float64), IO in (IOBuffer, IOContext{IOBuffer}, Base
9191
hardcoded_precompile_statements *= "precompile(Tuple{typeof(show), $IO, $T})\n"
9292
end
9393

94+
# Precompiles for Revise and other packages
9495
precompile_script = """
95-
# NOTE: these were moved to the end of Base.jl. TODO: move back here.
96-
# # Used by Revise & its dependencies
97-
# while true # force inference
98-
# delete!(push!(Set{Module}(), Base), Main)
99-
# m = first(methods(+))
100-
# delete!(push!(Set{Method}(), m), m)
101-
# empty!(Set())
102-
# push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
103-
# (setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
104-
# (setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
105-
# (setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
106-
# (setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
107-
# (setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
108-
# Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
109-
# Dict(Base => [:(1+1)])[Base]
110-
# Dict(:one => [1])[:one]
111-
# Dict("abc" => Set())["abc"]
112-
# pushfirst!([], sum)
113-
# get(Base.pkgorigins, Base.PkgId(Base), nothing)
114-
# sort!([1,2,3])
115-
# unique!([1,2,3])
116-
# cumsum([1,2,3])
117-
# append!(Int[], BitSet())
118-
# isempty(BitSet())
119-
# delete!(BitSet([1,2]), 3)
120-
# deleteat!(Int32[1,2,3], [1,3])
121-
# deleteat!(Any[1,2,3], [1,3])
122-
# Core.svec(1, 2) == Core.svec(3, 4)
123-
# # copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(which(+, (Int, Int)), [Int, Int], Core.svec())))
124-
# any(t->t[1].line > 1, [(LineNumberNode(2,:none),:(1+1))])
125-
# break # end force inference
126-
# end
96+
for match = Base._methods(+, (Int, Int), -1, Base.get_world_counter())
97+
m = match.method
98+
delete!(push!(Set{Method}(), m), m)
99+
copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(match), typemax(UInt)))
100+
101+
empty!(Set())
102+
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
103+
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
104+
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
105+
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
106+
(setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
107+
(setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
108+
Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
109+
Dict(Base => [:(1+1)])[Base]
110+
Dict(:one => [1])[:one]
111+
Dict("abc" => Set())["abc"]
112+
pushfirst!([], sum)
113+
get(Base.pkgorigins, Base.PkgId(Base), nothing)
114+
sort!([1,2,3])
115+
unique!([1,2,3])
116+
cumsum([1,2,3])
117+
append!(Int[], BitSet())
118+
isempty(BitSet())
119+
delete!(BitSet([1,2]), 3)
120+
deleteat!(Int32[1,2,3], [1,3])
121+
deleteat!(Any[1,2,3], [1,3])
122+
Core.svec(1, 2) == Core.svec(3, 4)
123+
any(t->t[1].line > 1, [(LineNumberNode(2,:none), :(1+1))])
124+
125+
# Code loading uses this
126+
sortperm(mtime.(readdir(".")), rev=true)
127+
# JLLWrappers uses these
128+
Dict{Base.UUID,Set{String}}()[Base.UUID("692b3bcd-3c85-4b1f-b108-f13ce0eb3210")] = Set{String}()
129+
get!(Set{String}, Dict{Base.UUID,Set{String}}(), Base.UUID("692b3bcd-3c85-4b1f-b108-f13ce0eb3210"))
130+
eachindex(IndexLinear(), Expr[])
131+
push!(Expr[], Expr(:return, false))
132+
vcat(String[], String[])
133+
k, v = (:hello => nothing)
134+
precompile(Base.indexed_iterate, (Pair{Symbol, Union{Nothing, String}}, Int))
135+
precompile(Base.indexed_iterate, (Pair{Symbol, Union{Nothing, String}}, Int, Int))
136+
# Preferences uses these
137+
precompile(Base.get_preferences, (Base.UUID,))
138+
precompile(Base.record_compiletime_preference, (Base.UUID, String))
139+
get(Dict{String,Any}(), "missing", nothing)
140+
delete!(Dict{String,Any}(), "missing")
141+
for (k, v) in Dict{String,Any}()
142+
println(k)
143+
end
144+
145+
break # only actually need to do this once
146+
end
127147
"""
128148

129149
julia_exepath() = joinpath(Sys.BINDIR, Base.julia_exename())

0 commit comments

Comments
 (0)