Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heavy invalidations from == overloads #523

Closed
ChrisRackauckas opened this issue Dec 24, 2021 · 1 comment
Closed

Heavy invalidations from == overloads #523

ChrisRackauckas opened this issue Dec 24, 2021 · 1 comment

Comments

@ChrisRackauckas
Copy link
Member

The following:

# From: https://timholy.github.io/SnoopCompile.jl/stable/snoopr/
using SnoopCompile
invalidations = @snoopr begin
    using DifferentialEquations

    function lorenz(du,u,p,t)
     du[1] = 10.0(u[2]-u[1])
     du[2] = u[1]*(28.0-u[3]) - u[2]
     du[3] = u[1]*u[2] - (8/3)*u[3]
    end
    u0 = [1.0;0.0;0.0]
    tspan = (0.0,100.0)
    prob = ODEProblem(lorenz,u0,tspan)
    alg = Rodas5()
    tinf = solve(prob,alg)
end;

trees = SnoopCompile.invalidation_trees(invalidations);

@show length(SnoopCompile.uinvalidated(invalidations)) # show total invalidations

show(trees[end]) # show the most invalidated method

# Count number of children (number of invalidations per invalidated method)
n_invalidations = map(trees) do methinvs
    SnoopCompile.countchildren(methinvs)
end

found ChainRulesCore as one of the main culprits for invalidations:

julia> trees[end-2]
inserting ==(a, b::ChainRulesCore.AbstractThunk) in ChainRulesCore at C:\Users\accou\.julia\packages\ChainRulesCore\sHMAp\src\tangent_types\thunks.jl:27 invalidated:      
   backedges: 1: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Base.UUID, ::Any) (4 children)
              2: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Tokenize.Tokens.Kind, ::Any) (6 children)
              3: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Module, ::Any) (8 children)
              4: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Method, ::Any) (24 children)
              5: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Core.TypeName, ::Any) (70 children)
              6: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Symbol, ::Any) (213 children)


julia> trees[end-1]
inserting ==(a::ChainRulesCore.AbstractThunk, b) in ChainRulesCore at C:\Users\accou\.julia\packages\ChainRulesCore\sHMAp\src\tangent_types\thunks.jl:26 invalidated:      
   backedges:  1: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::LineNumberNode) (1 children)
               2: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Module) (1 children)
               3: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Core.MethodInstance) (1 children)
               4: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Base.CoreLogging.LogLevel) (2 children)
               5: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Core.Compiler.InferenceResult) (2 children)
               6: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Task) (4 children)
               7: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Base.UUID) (5 children)
               8: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Tokenize.Tokens.Kind) (5 children)
               9: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::typeof(show)) (6 children)
              10: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::REPL.LineEdit.Prompt) (7 children)
              11: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Atom.OutlineItem) (7 children)
              12: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Nothing) (22 children)
              13: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::Symbol) (152 children)
              14: superseding ==(x, y) in Base at Base.jl:119 with MethodInstance for ==(::Any, ::CSTParser.EXPR) (238 children)

But those overloads are completely unnecessary anyways as you can always just do a isa AbstractThunk etc. stuff, and it was only added for testing:

#367

Seems like @johnnychen94 noticed this too that these "only for test" overloads are now some of the main compile time culprits in the language... not a good trade-off 😅

ChrisRackauckas added a commit that referenced this issue Dec 24, 2021
See #523 . Seems to only be used for tests according to the PR but it's a major compile time problem, so it doesn't make sense to keep them. This can be marked breaking if it breaks downstream, but it's rather easy to update downstream AD packages for this so the value proposition is pretty clear.
ChrisRackauckas added a commit that referenced this issue Mar 19, 2022
See #523 . Seems to only be used for tests according to the PR but it's a major compile time problem, so it doesn't make sense to keep them. This can be marked breaking if it breaks downstream, but it's rather easy to update downstream AD packages for this so the value proposition is pretty clear.
@ChrisRackauckas
Copy link
Member Author

This was solved.

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

No branches or pull requests

1 participant