JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.09k stars 5.43k forks source link

Loading Dates invalidates Base.typeinfo_implicit(::Any) #54987

Open mkitti opened 3 weeks ago

mkitti commented 3 weeks ago

Loading the standard library Dates.jl invalidates Base.typeinfo_implicit(::Any). Note that Dates.jl is a dependency of Pkg.jl.

julia> using SnoopCompileCore

julia> invalidations = @snoopr using Dates
52-element Vector{Any}:
  MethodInstance for Base.typeinfo_implicit(::Any)
 1
  MethodInstance for Base.typeinfo_implicit(::Any)
 2
  MethodInstance for Base._all(::typeof(Base.typeinfo_implicit), ::Tuple, ::Colon)
 2
  MethodInstance for all(::typeof(Base.typeinfo_implicit), ::Tuple)
 3
  MethodInstance for Base.typeinfo_implicit(::Any)
 4
  MethodInstance for Base.typeinfo_implicit(::DataType)
 4
  MethodInstance for Base._all(::typeof(Base.typeinfo_implicit), ::Tuple{DataType, DataType}, ::Colon)
 5
  MethodInstance for all(::typeof(Base.typeinfo_implicit), ::Tuple{DataType, DataType})
 6
 ⋮
 2
  MethodInstance for Base._all(::typeof(Base.typeinfo_implicit), ::Tuple, ::Colon)
 1
  MethodInstance for Base._all_tuple(::typeof(Base.typeinfo_implicit), ::Bool, ::Any, ::Vararg{Any})
 1
  MethodInstance for Base.typeinfo_implicit(::DataType)
 1
  MethodInstance for Base.typeinfo_implicit(::Any)
  "jl_method_table_insert"
  MethodInstance for Base.typeinfo_implicit(::DataType)
  "jl_method_table_insert"
  MethodInstance for Base.typeinfo_implicit(::Any)
  "invalidate_mt_cache"
  typeinfo_implicit(::Type{Month}) @ Dates ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/Dates/src/periods.jl:23
  "jl_method_table_insert"

julia> using SnoopCompile
[ Info: Precompiling SnoopCompile [aa65fe97-06da-5843-b5b1-d5d13cad87d2] (cache misses: invalid header (6))

julia> trees = invalidation_trees(invalidations)
1-element Vector{SnoopCompile.MethodInvalidations}:
 inserting typeinfo_implicit(::Type{Month}) @ Dates ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/Dates/src/periods.jl:23 invalidated:
   backedges: 1: superseding typeinfo_implicit(T) @ Base arrayshow.jl:550 with MethodInstance for Base.typeinfo_implicit(::Any) (22 children)
   1 mt_cache

julia> versioninfo()
Julia Version 1.12.0-DEV.801
Commit 41bde01c8d6 (2024-06-29 18:24 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × AMD FX(tm)-8350 Eight-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-17.0.6 (ORCJIT, bdver1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

The generic typeinfo_implicit is defined here: https://github.com/JuliaLang/julia/blob/00c700ee58f3393c0b733497cd2520129a0907c6/base/arrayshow.jl#L549-L559

It is invalidated here: https://github.com/JuliaLang/julia/blob/00c700ee58f3393c0b733497cd2520129a0907c6/stdlib/Dates/src/periods.jl#L23

mkitti commented 3 weeks ago

Note that this also affects Julia 1.11.0-rc1:

julia> trees = invalidation_trees(invalidations)
1-element Vector{SnoopCompile.MethodInvalidations}:
 inserting typeinfo_implicit(::Type{Month}) @ Dates ~/.julia/juliaup/julia-1.11.0-rc1+0.x64.linux.gnu/share/julia/stdlib/v1.11/Dates/src/periods.jl:23 invalidated:
   backedges: 1: superseding typeinfo_implicit(T) @ Base arrayshow.jl:550 with MethodInstance for Base.typeinfo_implicit(::Any) (22 children)
   1 mt_cache

julia> versioninfo()
Julia Version 1.11.0-rc1
Commit 3a35aec36d1 (2024-06-25 10:23 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × AMD FX(tm)-8350 Eight-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, bdver1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)