Continuing from Julia v1.9.0-beta2 is fast and using Tim’s recipe
using SnoopCompileCore
invs = @snoopr using GMT
tinf = @snoopi_deep plot(rand(5,2));
using SnoopCompile
trees = invalidation_trees(invs);
taletrees = precompile_blockers(trees, tinf)
I found that the major culprit was this line I had in startup.jl
to print UInt's
in a human readable way (I hate when they printed in hexadecimal).
Base.show(io::IO, x::T) where {T<:Union{UInt, UInt64, UInt32, UInt16, UInt8}} = Base.print(io, x)
Removing it made already a big difference (though I’m again screwed in search of an alternative).
julia> @time using GMT
1.808663 seconds (3.46 M allocations: 205.896 MiB, 4.76% gc time, 0.22% compilation time)
julia> @time @eval plot(rand(5,2))
2.616777 seconds (7.55 M allocations: 470.434 MiB, 6.38% gc time, 162.89% compilation time: 45% of which was recompilation)
(it used to take ~4.5 sec)
| | |_| | | | (_| | | Version 1.10.0-DEV.207 (2022-12-28)
_/ |\__'_|_|_|\__'_| | Commit 9448c89652 (5 days old master)
|__/ |
julia> include("c:/v/test_gmt1.jl")
1-element Vector{SnoopCompile.StaleTree}:
inserting eltype(::Type{JuliaInterpreter.ExprSplitter}) @ JuliaInterpreter C:\Users\joaqu\.julia\packages\JuliaInterpreter\8vzXf\src\construct.jl:430 invalidated:
mt_backedges: 1: MethodInstance for SubArray(::IndexCartesian, ::P, ::I, ::Tuple{Vararg{Any, N}}) where {P<:GMTdataset, I<:Tuple, N} at depth 1 with 5 children blocked InferenceTimingNode: 0.004436/0.073617 on GMT.make_color_column(::Dict{Symbol, Any}, ::String, ::String, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool, ::Bool, ::Vector{String}, ::Matrix{Float64}, nothing::Nothing) with 16 direct children
2: MethodInstance for SubArray(::IndexLinear, ::P, ::I, ::Tuple{Vararg{Any, N}}) where {P<:(Array), I<:Tuple, N} at depth 1 with 17 children blocked 1.4152226000000003 inclusive time for 2 nodes
There is only one invalidation coming from JuliaInterpreter
, which is not a GMT’s dependency (nor indirectly). It turns out it is a Revise
dependency and I have Revise
in my startup.jl
.
Without Revise
julia> @time @eval plot(rand(5,2))
0.687842 seconds (1.08 M allocations: 71.042 MiB, 2.03% gc time, 146.57% compilation time: 33% of which was recompilation)
Finaly the load time
This is a longer list but all references seem to come from dependecies of PrettyTables
like LatexStrings
and StringManipulation
julia> include(“c:/v/test_gmt1.jl”)
SnoopCompile.StaleTree
julia> trees
7-element Vector{SnoopCompile.MethodInvalidations}:
inserting firstindex(s::LaTeXStrings.LaTeXString) @ LaTeXStrings C:\Users\joaqu\.julia\packages\LaTeXStrings\pJ7vn\src\LaTeXStrings.jl:108 invalidated:
backedges: 1: superseding firstindex(s::AbstractString) @ Base strings\basic.jl:180 with MethodInstance for firstindex(::AbstractString) (1 children)
inserting codeunits(s::LaTeXStrings.LaTeXString) @ LaTeXStrings C:\Users\joaqu\.julia\packages\LaTeXStrings\pJ7vn\src\LaTeXStrings.jl:124 invalidated:
mt_backedges: 1: signature Tuple{typeof(codeunits), Any} triggered MethodInstance for Base.cwstring(::AbstractString) (3 children)
backedges: 1: superseding codeunits(s::AbstractString) @ Base strings\basic.jl:785 with MethodInstance for codeunits(::AbstractString) (1 children)
inserting Base.IteratorSize(::Type{R}) where R<:Union{AbstractColumns, AbstractRow} @ Tables C:\Users\joaqu\.julia\packages\Tables\T7rHm\src\Tables.jl:179 invalidated:
backedges: 1: superseding Base.IteratorSize(::Type) @ Base generator.jl:94 with MethodInstance for Base.IteratorSize(::Type{<:AbstractString}) (5 children)
112 mt_cache
inserting lastindex(s::LaTeXStrings.LaTeXString) @ LaTeXStrings C:\Users\joaqu\.julia\packages\LaTeXStrings\pJ7vn\src\LaTeXStrings.jl:109 invalidated:
backedges: 1: superseding lastindex(s::AbstractString) @ Base strings\basic.jl:181 with MethodInstance for lastindex(::AbstractString) (5 children)
inserting eltype(::Type{Tables.NamedTupleIterator{Tables.Schema{names, types}, T}}) where {names, types, T} @ Tables C:\Users\joaqu\.julia\packages\Tables\T7rHm\src\namedtuples.jl:36 invalidated:
backedges: 1: superseding eltype(::Type) @ Base abstractarray.jl:233 with MethodInstance for eltype(::Type) (6 children)
34 mt_cache
inserting sizeof(s::LaTeXStrings.LaTeXString) @ LaTeXStrings C:\Users\joaqu\.julia\packages\LaTeXStrings\pJ7vn\src\LaTeXStrings.jl:125 invalidated:
backedges: 1: superseding sizeof(s::AbstractString) @ Base strings\basic.jl:179 with MethodInstance for sizeof(::AbstractString) (15 children)
inserting convert(::Type{String}, d::StringManipulation.Decoration) @ StringManipulation C:\Users\joaqu\.julia\packages\StringManipulation\wxRU4\src\decorations.jl:193 invalidated:
mt_backedges: 1: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Base.UUID}, ::Any, ::Any) (0 children)
2: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Union{Bool, String}}, ::Any, ::Any) (0 children)
3: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Union{Nothing, String}}, ::Any, ::Any) (0 children)
4: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Nothing}, ::Nothing, ::Any) (0 children)
5: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Vector{String}, ::Any, ::Int64) (0 children)
6: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for push!(::Vector{String}, ::Any) (0 children)
7: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Union{Base.SHA1, String}}, ::Any, ::Any) (0 children)
8: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Function}, ::Any, ::Any) (0 children)
9: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Union{String, Vector{String}}}, ::Any, ::Any) (0 children)
10: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, String}, ::Any, ::Any) (0 children)
11: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for (::Base.var"#cvt1#1"{Tuple{String, String, Base.UUID}})(::Int64) (0 children)
12: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for (::Base.var"#cvt1#1"{Tuple{String, Union{Nothing, VersionNumber}}})(::Int64) (0 children)
13: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Any}, ::Any, ::Any) (0 children)
14: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Vector{Pkg.Types.Stage1}}, ::Vector{Pkg.Types.Stage1}, ::Any) (0 children)
15: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for (::Base.var"#cvt1#1"{Tuple{Base.UUID, String, String, VersionNumber}})(::Int64) (0 children)
16: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Test.Fail(::Symbol, ::Any, ::Any, ::Any, ::Nothing, ::LineNumberNode, ::Bool) (0 children)
17: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Test.Fail(::Symbol, ::Any, ::Any, ::Any, ::Any, ::LineNumberNode, ::Bool) (0 children)
18: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Test.Fail(::Symbol, ::Any, ::Any, ::Nothing, ::Nothing, ::LineNumberNode, ::Bool) (0 children)
19: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Base.UUID}, ::Base.UUID, ::Any) (0 children)
20: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Test.Fail(::Symbol, ::Any, ::Any, ::Bool, ::Nothing, ::LineNumberNode, ::Bool) (0 children)
21: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Pkg.Types.Compat}, ::Any, ::Any) (0 children)
22: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, Vector{String}}, ::Vector{String}, ::Any) (0 children)
23: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::IdDict{Any, String}, ::Any, ::Any) (1 children)
24: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for setindex!(::Dict{String, String}, ::Any, ::String) (1 children)
25: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for convert(::Type{Pair{String, String}}, ::Pair{String}) (1 children)
26: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Logging.var"#handle_message#3"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Base.CoreLogging.handle_message), ::Logging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) (1 children)
27: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Logging.var"#handle_message#3"(::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}}, ::typeof(Base.CoreLogging.handle_message), ::Logging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) (1 children)
28: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Test.Error(::Symbol, ::Any, ::Any, ::Vector{Any}, ::LineNumberNode) (1 children)
29: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for REPL.LineEdit.PrefixSearchState(::Any, ::Any, ::Any, ::Any) (1 children)
30: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for REPL.LineEditREPL(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) (1 children)
31: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Test.Error(::Symbol, ::Any, ::Bool, ::Nothing, ::LineNumberNode) (1 children)
32: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Test.Error(::Symbol, ::Any, ::Any, ::Nothing, ::LineNumberNode) (2 children)
33: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Test.Error(::Symbol, ::Any, ::Any, ::Any, ::LineNumberNode) (2 children)
34: signature Tuple{typeof(convert), Union{Type{Base.UUID}, Type{String}}, Any} triggered MethodInstance for (::Base.var"#cvt1#1"{Tuple{String, String, Base.UUID}})(::Int64) (3 children)
35: signature Tuple{typeof(convert), Union{Type{Base.UUID}, Type{VersionNumber}, Type{String}}, Any} triggered MethodInstance for (::Base.var"#cvt1#1"{Tuple{Base.UUID, String, String, VersionNumber}})(::Int64) (3 children)
36: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Base.CoreLogging.var"#handle_message#2"(::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}}, ::typeof(Base.CoreLogging.handle_message), ::Base.CoreLogging.SimpleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) (4 children)
37: signature Tuple{typeof(convert), Union{Type{String}, Type{Union{Nothing, VersionNumber}}}, Any} triggered MethodInstance for (::Base.var"#cvt1#1"{Tuple{String, Union{Nothing, VersionNumber}}})(::Int64) (4 children)
38: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for REPL.REPLHistoryProvider(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) (17 children)
39: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for convert(::Type{Union{Nothing, String}}, ::Any) (48 children)
40: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Pkg.Types.Compat(::Pkg.Versions.VersionSpec, ::Any) (121 children)
41: signature Tuple{typeof(convert), Type{String}, Any} triggered MethodInstance for Pkg.Registry.verify_compressed_registry_toml(::String) (156 children)