jonniedie / ComponentArrays.jl

Arrays with arbitrarily nested named components.
MIT License
287 stars 34 forks source link

fix invalidations #181

Closed ranocha closed 1 year ago

ranocha commented 1 year ago

I found quite a few invalidations using the following code with Julia v1.8.3:

julia> using Pkg; Pkg.activate(temp=true); Pkg.develop("ComponentArrays"); Pkg.add("Trixi")

julia> using SnoopCompileCore; invalidations = @snoopr(using Trixi); using SnoopCompile

julia> length(uinvalidated(invalidations))
1655

julia> trees = invalidation_trees(invalidations)
...
 inserting CartesianIndices(ax::Tuple{Vararg{ComponentArrays.CombinedAxis}}) in ComponentArrays at /home/hendrik/.julia/dev/ComponentArrays/src/axis.jl:205 invalidated:
   backedges: 1: superseding CartesianIndices(indices::R) where {N, R<:Tuple{Vararg{OrdinalRange{Int64, Int64}, N}}} in Base.IteratorsMD at multidimensional.jl:249 with MethodInstance for CartesianIndices(::Tuple{Vararg{Base.OneTo{Int64}}}) (180 children)
   37 mt_cache
...

julia> ascend(trees[end-2].backedges[end])
Choose a call for analysis (q to quit):
^      #vreduce#128(::Int64, ::typeof(LoopVectorization.vreduce), ::typeof(min), ::Array{Int64, 3})
         (::LoopVectorization.var"#vreduce##kw")(::NamedTuple{(:dims,), Tuple{Int64}}, ::typeof(LoopVectorization
           _vminimum(::Array{Int64, 3}, ::Int64)
...

The problem is that ComponentArrays.jl overwrites an existing method of CartesianIndices for an empty tuple. I fixed that, resulting in

julia> using Pkg; Pkg.activate(temp=true); Pkg.develop("ComponentArrays"); Pkg.add("Trixi")

julia> using SnoopCompileCore; invalidations = @snoopr(using Trixi); using SnoopCompile

julia> length(uinvalidated(invalidations))
1507

julia> trees = invalidation_trees(invalidations)

and the invalidations reported above are gone.

codecov-commenter commented 1 year ago

Codecov Report

Merging #181 (9d10e15) into master (cbb24ef) will not change coverage. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #181   +/-   ##
=======================================
  Coverage   73.49%   73.49%           
=======================================
  Files          20       20           
  Lines         679      679           
=======================================
  Hits          499      499           
  Misses        180      180           
Impacted Files Coverage Δ
src/axis.jl 85.71% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more