timholy / SnoopCompile.jl

Provide insights about latency (TTFX) for Julia packages
https://timholy.github.io/SnoopCompile.jl/dev/
Other
309 stars 48 forks source link

Doc recommends considering backedges[end] but this might not exist #210

Closed tlienart closed 3 years ago

tlienart commented 3 years ago

In playing with @snoopr, I got

inserting joinpath(uri::URIs.URI, parts::String...) in URIs at /Users/tlienart/.julia/packages/URIs/1jrj1/src/URIs.jl:466 invalidated:
   mt_backedges: 1: signature Tuple{typeof(joinpath), Any, String} triggered MethodInstance for Artifacts.jointail(::Any, ::String) (0 children)

following the docs I tried:

method_invalidations = trees[1]
root = method_invalidations.backedges[end]

this failed with

ERROR: BoundsError: attempt to access 0-element Vector{SnoopCompile.InstanceNode} at index [0]
Stacktrace:
 [1] getindex(A::Vector{SnoopCompile.InstanceNode}, i1::Int64)
   @ Base ./array.jl:787
 [2] top-level scope
   @ none:1

so maybe the doc should just clarify why there may not be such a backedge?

timholy commented 3 years ago

Good point. There's a section right ~below~above that, https://timholy.github.io/SnoopCompile.jl/stable/snoopr/#mt_backedges-invalidations, that covers the other type of backedge, the mt_backedges. Would it help to insert a note pointing ~forward~back to that section?

tlienart commented 3 years ago

And, while I'm at it, if I see something like:

julia> method_invalidations
inserting joinpath(uri::URIs.URI, parts::String...) in URIs at /Users/tlienart/.julia/packages/URIs/1jrj1/src/URIs.jl:466 invalidated:
   mt_backedges: 1: signature Tuple{typeof(joinpath), Any, String} triggered MethodInstance for Artifacts.jointail(::Any, ::String) (0 children)

julia> sig, root = method_invalidations.mt_backedges[end]
Pair{Any, SnoopCompile.InstanceNode}(Tuple{typeof(joinpath), Any, String}, MethodInstance for Artifacts.jointail(::Any, ::String) at depth 0 with 0 children)

julia> root
MethodInstance for Artifacts.jointail(::Any, ::String) at depth 0 with 0 children

what should I do to fix it? (sorry, I feel like I'm re-learning Julia with SnoopCompile... 🙈 )

timholy commented 3 years ago

Generally ascend(root). Cthulhu is complicated but really amazing. Did you see the link to the video? https://www.youtube.com/watch?v=7VbXbI6OmYo

timholy commented 3 years ago

I feel like I'm re-learning Julia with SnoopCompile

I hear you. It definitely takes you into territory you've probably never explored before. Hopefully you emerge feeling like you've learned a few arts that are actually useful...but if not, I'd like to hear about it.

tlienart commented 3 years ago

I'll read the docs and watch the videos, thanks Tim!

timholy commented 3 years ago

Oh, by the way: "0 children" roots are probably not worth your time. Focus on ones with bigger impact. Just loading Franklin, I get 323 invalidations, all from HTTP.jl. Unfortunately those look hard to solve, so my recommendation is to ignore them. (They only affect REPL and not your code.)

In your case, you are getting more invalidations when you run the test suite, and those do invalidate Franklin methods. I'd consider starting with that DataStructures one I noted elsewhere.