Skip to content

Commit ab37ee5

Browse files
IanButterworthKristofferC
authored andcommittedMar 15, 2024
move precompile workload back from Base (#53679)
(cherry picked from commit 26b3b5f)
1 parent 760f368 commit ab37ee5

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
@@ -567,61 +567,6 @@ end_base_include = time_ns()
567567
const _sysimage_modules = PkgId[]
568568
in_sysimage(pkgid::PkgId) = pkgid in _sysimage_modules
569569

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

627572
# 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)
Please sign in to comment.