Skip to content

Conversation

@adranka
Copy link

@adranka adranka commented Nov 22, 2025

Some changes to the way hash is implemented in the package:

  • Changes the hash function to use the 2 argument version as recommended in the Julia docs
  • Applies the hash function recursively
  • Makes BusinessDays.jl free of invalidations (at least with Base)

Before:

julia> using SnoopCompileCore

julia> invs = @snoop_invalidations using BusinessDays
Precompiling BusinessDays finished.
  1 dependency successfully precompiled in 2 seconds
SnoopCompileCore.InvalidationLists(Any[], Any[MethodInstance for Base.hashindex(::Any, ::Int64), 1, MethodInstance for Base.rehash!(::Dict, ::Int64), 2, MethodInstance for Base.var"#sizehint!#303"(::Bool, ::typeof(sizehint!), ::Dict, ::Int64), 3, MethodInstance for sizehint!(::Dict, ::Int64), 4, MethodInstance for (::Type{Dict{_A, _B}} where {_A, _B})(::Tuple{Pair{String, String}, Vararg{Pair}}), 5  …  MethodInstance for Base.var"#showerror#822"(::Bool, ::typeof(showerror), ::IOContext{Base.TTY}, ::BoundsError, ::Vector{Base.StackTraces.StackFrame}), 3, MethodInstance for Core.kwcall(::@NamedTuple{backtrace::Bool}, ::typeof(showerror), ::IOContext{Base.TTY}, ::BoundsError, ::Vector{Base.StackTraces.StackFrame}), 4, MethodInstance for Base.var"#showerror#822"(::Bool, ::typeof(showerror), ::IOContext{Base.TTY}, ::MethodError, ::Vector{Base.StackTraces.StackFrame}), 3, MethodInstance for hash(::Any), "jl_method_table_insert", hash(a::BusinessDays.Australia) @ BusinessDays ~/code/original_code/BusinessDays.jl/src/calendars/australia.jl:35, "jl_method_table_insert"])

julia> using SnoopCompile, AbstractTrees

julia> trees = invalidation_trees(invs)
1-element Vector{SnoopCompile.MethodInvalidations}:
 inserting hash(a::BusinessDays.Australia) @ BusinessDays ~/code/original_code/BusinessDays.jl/src/calendars/australia.jl:35 invalidated:
   backedges: 1: superseding hash(x) @ Base hashing.jl:28 with MethodInstance for hash(::Any) (1400 children)

After:

julia> using SnoopCompileCore

julia> invs = @snoop_invalidations using BusinessDays
Precompiling BusinessDays finished.
  1 dependency successfully precompiled in 2 seconds. 3 already precompiled.
SnoopCompileCore.InvalidationLists(Any[], Any[])

julia> using SnoopCompile, AbstractTrees

julia> trees = invalidation_trees(invs)
SnoopCompile.MethodInvalidations[]

@felipenoris Let me know if this looks good!

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.

1 participant