JuliaLang / Pkg.jl

Pkg - Package manager for the Julia programming language
https://pkgdocs.julialang.org
Other
609 stars 251 forks source link

improve precompilation for `st` in the Pkg REPL #3893

Closed KristofferC closed 1 month ago

KristofferC commented 1 month ago

Measurement:

julia> using Pkg, REPL

julia> const REPLExt = Base.get_extension(Pkg, :REPLExt)
REPLExt

julia> @time @eval REPLExt.do_cmds(Base.active_repl, "st")
Project Pkg v1.12.0
Status `~/JuliaPkgs/Pkg.jl/Project.toml`
  [56f22d72] Artifacts v1.11.0
  [ade2ca70] Dates v1.11.0
  [f43a241f] Downloads v1.6.0
  [7b1f6079] FileWatching v1.11.0
  [76f85450] LibGit2 v1.11.0
  [8f399da3] Libdl v1.11.0
  [56ddb016] Logging v1.11.0
  [d6f4376e] Markdown v1.11.0
  [de0858da] Printf v1.11.0
  [9a3f8284] Random v1.11.0
  [ea8e919c] SHA v0.7.0
  [fa267f1f] TOML v1.0.3
  [a4e569a6] Tar v1.10.0
  [cf7118a7] UUIDs v1.11.0
  [3f19e933] p7zip_jll v17.5.0+0

Before:

  1.232465 seconds (4.30 M allocations: 254.177 MiB, 7.91% gc time, 79.78% compilation time: 3% of which was recompilation)

After

  0.629539 seconds (1.92 M allocations: 131.477 MiB, 15.28% gc time, 52.50% compilation time: 8% of which was recompilation)

On 1.10 we have

julia> @time @eval Pkg.REPLMode.do_cmd(Base.active_repl, "st")
  0.431920 seconds (2.05 M allocations: 163.018 MiB, 4.72% gc time, 18.10% compilation time)
gbaraldi commented 1 month ago

Adding

    Base.precompile(Tuple{typeof(Base.keys), Base.Dict{String, Base.Dict{String, Pkg.REPLMode.CommandSpec}}})
    Base.precompile(Tuple{typeof(Base.getproperty), Base.KeySet{String, Base.Dict{String, Base.Dict{String, Pkg.REPLMode.CommandSpec}}}, Symbol})
    Base.precompile(Tuple{Type{Pkg.REPLMode.QString}, String, Bool})
    Base.precompile(Tuple{typeof(REPL.LineEdit.complete_line), REPLExt.PkgCompletionProvider, REPL.LineEdit.PromptState})

makes the lag when typing on the Pkg repl go away.

KristofferC commented 1 month ago

The last two of those are already in this PR and the first two are pretty much instant to compile so I don't think those make a difference in practice. Also, in this PR, typing in the REPL seems instant to me.

gbaraldi commented 1 month ago

Oh I missed the complete_line one (I imagine it's the one that makes a difference)