Invalidation checker for packages [code snippet]

Hey,

I just wanted to share this code snippet which can be helpful to find where the imported invalidation comes from.

using SnoopCompileCore
using SnoopCompile
using SnoopCompile: countchildren
using Pkg
using Printf

toprints=[]

for (package, version) in Pkg.installed() # Pkg.depenencies()
@show package
invs = @snoopr @eval using $(Symbol(package))
trees = invalidation_trees(invs)
push!(toprints, (pkgname=package, invfunc=length(trees), sumchildren=sum([countchildren(tree) for tree in trees]), invalidations=length(invs)) )
end

sort!(toprints, by=x -> x[:sumchildren], rev=true)
for toprint in toprints
@printf "%-20s: invalidations: %3d which invalidated: %5d children (%5d invalidations)\n" toprint[:pkgname] toprint[:invfunc] toprint[:sumchildren] toprint[:invalidations]
end

For me I checked some of the package whether I really need them and just reduced a little latency by removing them.

StatsPlots          : invalidations:  24 which invalidated:  2933 children ( 6726  invalidations)
PyCall              : invalidations:   7 which invalidated:  1958 children ( 4285  invalidations)
JSON3               : invalidations:   4 which invalidated:  1438 children ( 2896  invalidations)
EllipsisNotation    : invalidations:   7 which invalidated:  1066 children ( 2523  invalidations)
HTTP                : invalidations:   4 which invalidated:   532 children ( 1110  invalidations)
JLD2                : invalidations:   3 which invalidated:   387 children (  851  invalidations)
DataFrames          : invalidations:   8 which invalidated:   363 children ( 1362  invalidations)
ORCA                : invalidations:   5 which invalidated:   276 children (  590  invalidations)
Flux                : invalidations:  22 which invalidated:   193 children ( 2611  invalidations)
JuliaFormatter      : invalidations:   2 which invalidated:   151 children (  346  invalidations)
JLD                 : invalidations:   8 which invalidated:   127 children (  335  invalidations)
BenchmarkTools      : invalidations:   2 which invalidated:   103 children (  216  invalidations)
GeometryTypes       : invalidations:   9 which invalidated:    68 children (  260  invalidations)
Makie               : invalidations:   6 which invalidated:    34 children (  591  invalidations)
KernelDensity       : invalidations:   2 which invalidated:    26 children (   84  invalidations)
GraphPlot           : invalidations:   1 which invalidated:    14 children (   54  invalidations)
Zygote              : invalidations:   7 which invalidated:    12 children (  129  invalidations)
LoopVectorization   : invalidations:   1 which invalidated:     4 children (  466  invalidations)
MethodAnalysis      : invalidations:   0 which invalidated:     0 children (    0  invalidations)
Memoize             : invalidations:   0 which invalidated:     0 children (    0  invalidations)
OrderedCollections  : invalidations:   0 which invalidated:     0 children (    0  invalidations)
JuliaInterpreter    : invalidations:   0 which invalidated:     0 children (    0  invalidations)
FastClosures        : invalidations:   0 which invalidated:     0 children (    0  invalidations)
DataStructures      : invalidations:   0 which invalidated:     0 children (   20  invalidations)
Glob                : invalidations:   0 which invalidated:     0 children (    0  invalidations)
Distributions       : invalidations:   0 which invalidated:     0 children (   88  invalidations)
JSON2               : invalidations:   0 which invalidated:     0 children (    0  invalidations)
Formatting          : invalidations:   0 which invalidated:     0 children (    0  invalidations)
AbstractPlotting    : invalidations:   0 which invalidated:     0 children (    0  invalidations)
FileIO              : invalidations:   0 which invalidated:     0 children (    0  invalidations)
SnoopCompile        : invalidations:   0 which invalidated:     0 children (    0  invalidations)
PackageCompiler     : invalidations:   0 which invalidated:     0 children (    0  invalidations)
GLMakie             : invalidations:   0 which invalidated:     0 children (    0  invalidations)
CSV                 : invalidations:   0 which invalidated:     0 children (   16  invalidations)
Revise              : invalidations:   0 which invalidated:     0 children (    0  invalidations)
SnoopCompileCore    : invalidations:   0 which invalidated:     0 children (    0  invalidations)
ClusterManagers     : invalidations:   0 which invalidated:     0 children (    4  invalidations)
LRUCache            : invalidations:   0 which invalidated:     0 children (   60  invalidations)
Parameters          : invalidations:   0 which invalidated:     0 children (    0  invalidations)
Redis               : invalidations:   0 which invalidated:     0 children (    0  invalidations)
LightGraphs         : invalidations:   0 which invalidated:     0 children (    0  invalidations)
NetworkLayout       : invalidations:   0 which invalidated:     0 children (    0  invalidations)
DiffRules           : invalidations:   0 which invalidated:     0 children (    0  invalidations)
Colors              : invalidations:   0 which invalidated:     0 children (    0  invalidations)
WebSockets          : invalidations:   0 which invalidated:     0 children (    0  invalidations)
Crayons             : invalidations:   0 which invalidated:     0 children (    0  invalidations)
MacroTools          : invalidations:   0 which invalidated:     0 children (    0  invalidations)
ChainRulesCore      : invalidations:   0 which invalidated:     0 children (    0  invalidations)

I know it is not perfect. Any idea is appreciated.
Do you guys think it is useful?

5 Likes