Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use PrecompileTools mechanics to compile REPL #55782

Merged

Conversation

IanButterworth
Copy link
Sponsor Member

@IanButterworth IanButterworth commented Sep 16, 2024

Fixes #55778

Based on discussion here #55778 (comment)

With this ?reinterpret feels instant, with only these precompiles at the start.
Screenshot 2024-09-16 at 9 49 39 AM

@KristofferC
Copy link
Sponsor Member

It would be good to know why there is still stuff left. Just to understand it.

@IanButterworth
Copy link
Sponsor Member Author

Using #55763. All but one are recompilation
Screenshot 2024-09-16 at 10 19 35 AM

@IanButterworth
Copy link
Sponsor Member Author

% ./julia --start=no -q -ie 'using SnoopCompileCore; tinv = @snoop_invalidations(begin using REPL; help_result(line, mod::Module=Base) = Core.eval(mod, REPL._helpmode(IOBuffer(), line, mod)); help_result("reinterpret") end)'

julia> using SnoopCompile, AbstractTrees

julia> trees = invalidation_trees(tinv)
15-element Vector{SnoopCompile.MethodInvalidations}:
 inserting Core.Compiler.OptimizationParams(interp::REPL.REPLCompletions.REPLInterpreter) @ REPL.REPLCompletions ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPLCompletions.jl:566 invalidated:

 inserting Core.Compiler.InferenceParams(interp::REPL.REPLCompletions.REPLInterpreter) @ REPL.REPLCompletions ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPLCompletions.jl:565 invalidated:

 inserting get_inference_world(interp::REPL.REPLCompletions.REPLInterpreter) @ REPL.REPLCompletions ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPLCompletions.jl:567 invalidated:

 inserting get_inference_cache(interp::REPL.REPLCompletions.REPLInterpreter) @ REPL.REPLCompletions ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPLCompletions.jl:568 invalidated:

 inserting cache_owner(::REPL.REPLCompletions.REPLInterpreter) @ REPL.REPLCompletions ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPLCompletions.jl:569 invalidated:

 inserting may_optimize(::REPL.REPLCompletions.REPLInterpreter) @ REPL.REPLCompletions ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPLCompletions.jl:572 invalidated:

 inserting bail_out_toplevel_call(::REPL.REPLCompletions.REPLInterpreter, ::Core.Compiler.InferenceLoopState, ::Core.Compiler.InferenceState) @ REPL.REPLCompletions ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPLCompletions.jl:578 invalidated:

 inserting const_prop_argument_heuristic(interp::REPL.REPLCompletions.REPLInterpreter, arginfo::Core.Compiler.ArgInfo, sv::Core.Compiler.InferenceState) @ REPL.REPLCompletions ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPLCompletions.jl:676 invalidated:

 inserting write(io::IO, c::Base.AnnotatedChar) @ StyledStrings ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/StyledStrings/src/io.jl:270 invalidated:
   backedges: 1: superseding write(io::IO, x) @ Base io.jl:792 with MethodInstance for write(::IOBuffer, ::AbstractChar) (1 children)
   3 mt_cache

 inserting in(key_value::Pair, t::REPL.Terminals.TTYTerminal) @ REPL.Terminals ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/Terminals.jl:156 invalidated:
   backedges: 1: superseding in(key_value::Pair, io::IO) @ Base show.jl:420 with MethodInstance for in(::Pair{Symbol, TypeVar}, ::IO) (1 children)

 inserting display(d::REPL.REPLDisplay, x) @ REPL ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:503 invalidated:
   mt_backedges: 1: signature Tuple{typeof(display), AbstractDisplay, Any} triggered MethodInstance for display(::Any) (0 children)
                 2: signature Tuple{typeof(display), AbstractDisplay, Any} triggered MethodInstance for Base.Multimedia.xdisplayable(::AbstractDisplay, ::Any) (1 children)

 inserting haskey(t::REPL.Terminals.TTYTerminal, key) @ REPL.Terminals ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/Terminals.jl:157 invalidated:
   backedges: 1: superseding haskey(io::IO, key) @ Base show.jl:422 with MethodInstance for haskey(::IO, ::Symbol) (2 children)

 inserting displaysize(t::REPL.Terminals.UnixTerminal) @ REPL.Terminals ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/REPL/src/Terminals.jl:151 invalidated:
   mt_backedges: 1: signature Tuple{typeof(displaysize), Any} triggered MethodInstance for (::Base.Precompilation.var"#74#75"{Int64, Base.Precompilation.MiniProgressBar, Vector{String}, Bool, Dict{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}, String}, Set{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}}, String, String, Base.Precompilation.var"#ansi_moveup#58", Base.Event, Vector{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}}, Dict{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}, String}, Vector{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}}, Int64, Dict{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}, Bool}, Dict{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}, Bool}, Vector{Base.PkgId}, Dict{Base.PkgId, String}, Base.Precompilation.var"#color_string#38"{Bool}})() (0 children)
                 2: signature Tuple{typeof(displaysize), Any} triggered MethodInstance for (::Base.Precompilation.var"#76#77"{Vector{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}}, Int64, Base.Precompilation.MiniProgressBar, Vector{String}, Bool, Dict{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}, String}, Set{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}}, String, Base.Event, Vector{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}}, Dict{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}, String}, Vector{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}}, Int64, Dict{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}, Bool}, Dict{Tuple{Base.PkgId, Pair{Cmd, Base.CacheFlags}}, Bool}, Vector{Base.PkgId}, Dict{Base.PkgId, String}, Base.Precompilation.var"#color_string#38"{Bool}})(::IOBuffer) (5 children)
   backedges: 1: superseding displaysize(io::IO) @ Base stream.jl:568 with MethodInstance for displaysize(::IO) (26 children)

 inserting kwcall(::NamedTuple, ::typeof(printstyled), io::Base.AnnotatedIOBuffer, msg...) @ StyledStrings.Legacy ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/StyledStrings/src/legacy.jl:126 invalidated:
   backedges:  1: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol}, ::typeof(printstyled), ::IO, ::String, ::Any, ::String, ::Any, ::String) (1 children)
               2: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{bold::Bool, italic::Bool, underline::Bool, blink::Bool, reverse::Bool, hidden::Bool, color::Int64}, ::typeof(printstyled), ::IO, ::String) (2 children)
               3: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{bold::Bool, italic::Bool, underline::Bool, blink::Bool, reverse::Bool, hidden::Bool, color::Symbol}, ::typeof(printstyled), ::IO, ::Any, ::Symbol) (2 children)
               4: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{bold::Bool, italic::Bool, underline::Bool, blink::Bool, reverse::Bool, hidden::Bool, color::Int64}, ::typeof(printstyled), ::IO, ::Any, ::Symbol) (2 children)
               5: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol, bold::Bool}, ::typeof(printstyled), ::IO, ::Module, ::Char) (2 children)
               6: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol, bold::Bool}, ::typeof(printstyled), ::IO, ::String) (2 children)
               7: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol, bold::Bool}, ::typeof(printstyled), ::IO, ::String, ::DataType, ::String) (2 children)
               8: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol}, ::typeof(printstyled), ::IO, ::DataType) (2 children)
               9: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol}, ::typeof(printstyled), ::IO, ::Type) (2 children)
              10: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol}, ::typeof(printstyled), ::IO, ::String, ::Any, ::String) (2 children)
              11: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol, underline::Bool}, ::typeof(printstyled), ::IO, ::String, ::String, ::Int32) (3 children)
              12: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol}, ::typeof(printstyled), ::IO, ::String) (4 children)
              13: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{color::Symbol, underline::Bool}, ::typeof(printstyled), ::IO, ::String, ::String, ::Int64) (6 children)
              14: superseding kwcall(::NamedTuple, ::typeof(printstyled), io::IO, msg...) @ Base util.jl:141 with MethodInstance for Core.kwcall(::@NamedTuple{bold::Bool, italic::Bool, underline::Bool, blink::Bool, reverse::Bool, hidden::Bool, color::Symbol}, ::typeof(printstyled), ::IO, ::String) (91 children)

 inserting print(io::IO, c::Base.AnnotatedChar) @ StyledStrings ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.12/StyledStrings/src/io.jl:281 invalidated:
   backedges: 1: superseding print(io::IO, c::AbstractChar) @ Base char.jl:261 with MethodInstance for print(::IOBuffer, ::Base.AnnotatedChar{Char}) (40 children)
              2: superseding print(io::IO, c::AbstractChar) @ Base char.jl:261 with MethodInstance for print(::IOContext{IOStream}, ::Base.AnnotatedChar{Char}) (82 children)
              3: superseding print(io::IO, c::AbstractChar) @ Base char.jl:261 with MethodInstance for print(::IOContext{IOBuffer}, ::Base.AnnotatedChar{Char}) (309 children)
   3 mt_cache

@IanButterworth IanButterworth merged commit 02549d5 into JuliaLang:master Sep 17, 2024
7 checks passed
@KristofferC
Copy link
Sponsor Member

KristofferC commented Sep 17, 2024

3: superseding print(io::IO, c::AbstractChar) @ Base char.jl:261 with MethodInstance for print(::IOContext{IOBuffer}, ::Base.AnnotatedChar{Char}) (309 children)

IIRC, this is from the Expr printer where the value has a @nospecialize on it so it infers as Any and gets invalidated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REPL precompile script not caching methods from runtime dispatch
3 participants