-
Notifications
You must be signed in to change notification settings - Fork 52
Expose changes to Julia via @snoopi_deep to report timing profile breakdown of _all MethodInstances_ that are inferred during type inference
#139
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
Conversation
```julia
julia> module M
i(x) = x+3
i2(x) = x+2
h(a::Array) = i2(a[1]::Integer) + i(a[1]::Integer) + 2
g(y::Integer, x) = h(Any[y]) + Int(x)
end;
WARNING: replacing module M.
julia> SnoopCompileCore.@Snoopi begin
M.g(2,3.0)
end
3-element Vector{Tuple{Float64,Core.MethodInstance,Vector{Pair{Core.MethodInstance,Core.MethodInstance}}}}:
(0.00024819374084472656, MethodInstance for i(::Int64), [])
(0.0003299713134765625, MethodInstance for i2(::Int64), [])
(0.001934051513671875, MethodInstance for g(::Int64, ::Float64), [MethodInstance for g(::Int64, ::Float64) => MethodInstance for h(::Vector{Any}), MethodInstance for h(::Vector{Any}) => MethodInstance for i2(::Integer), MethodInstance for h(::Vector{Any}) => MethodInstance for i(::Integer)])
```
…erly verbose)
I _think_ this now does what we want?
```julia
julia> module M
i(x) = x+5
i2(x) = x+2
h(a::Array) = i2(a[1]::Integer) + i(a[1]::Integer) + 2
g(y::Integer, x) = h(Any[y]) + Int(x)
end;
WARNING: replacing module M.
julia> out = SnoopCompileCore.@Snoopi begin
M.g(2,3.0)
end
3-element Vector{Tuple{Float64,Core.MethodInstance,Vector{Pair{Core.MethodInstance,Core.MethodInstance}}}}:
(0.00022411346435546875, MethodInstance for i(::Int64), [])
(0.00024890899658203125, MethodInstance for i2(::Int64), [])
(0.0016169548034667969, MethodInstance for g(::Int64, ::Float64), [MethodInstance for g(::Int64, ::Float64) => MethodInstance for h(::Vector{Any}), MethodInstance for h(::Vector{Any}) => MethodInstance for i2(::Integer), MethodInstance for h(::Vector{Any}) => MethodInstance for i(::Integer)])
julia> SnoopCompile.collect_per_method_inference_timings(out, :(module M
i(x) = x+5
i2(x) = x+2
h(a::Array) = i2(a[1]::Integer) + i(a[1]::Integer) + 2
g(y::Integer, x) = h(Any[y]) + Int(x)
end))
Launching new julia process to run commands...
done.
[ Info: MethodInstance for i(::Int64): total: 0.00022411346435546875 : 0.034790221
Dict{Any,Float64} with 1 entry:
Tuple{typeof(i),Int64} => 0.0347902
Launching new julia process to run commands...
done.
[ Info: MethodInstance for i2(::Int64): total: 0.00024890899658203125 : 0.035098683
Dict{Any,Float64} with 1 entry:
Tuple{typeof(i2),Int64} => 0.0350987
Launching new julia process to run commands...
done.
[ Info: MethodInstance for g(::Int64, ::Float64): total: 0.0016169548034667969 : 0.046937507
Dict{Any,Float64} with 4 entries:
Tuple{typeof(i2),Integer} => 0.0110619
Tuple{typeof(h),Vector{Any}} => 0.025103
Tuple{typeof(i),Integer} => 0.00563928
Tuple{typeof(g),Int64,Float64} => 0.00513329
[ Info: Returning merged results:
Dict{Any,Float64} with 6 entries:
Tuple{typeof(i2),Integer} => 0.0110619
Tuple{typeof(h),Vector{Any}} => 0.025103
Tuple{typeof(i),Integer} => 0.00563928
Tuple{typeof(i2),Int64} => 0.0350987
Tuple{typeof(g),Int64,Float64} => 0.00513329
Tuple{typeof(i),Int64} => 0.0347902
julia>
```
Now working through some more isssues, like not missing edges and deduplicating edges and nodes.
- for more accurate timings, and - prevent stackoverflow
… of the graph each time?
… exclusive times! :)
Make the functions more readable by printing with a pretty-printed function signature instead of a type tuple. Note though that this isn't ideal since the type tuple ends up as the _typeof_ the function, not the function instance. And not all callable objects are singletons, so you cannot safely call instance on it. Instead, we need to adjust the julia source to produce better records.
7070c0e to
44d9f2f
Compare
- src/parcel_snoopi_deep.jl - SnoopCompileCore/src/snoopi_deep.jl - test/snoopi_deep.jl
44d9f2f to
4e6b74f
Compare
@KristofferC - sorry i never responded to this. I had the same idea at first, but since this returns an entirely different data structure, and is used with entirely different helper functions, it doesn't seem to make sense to me to put them in the same macro. |
|
Alright, tests are passing, and I'm finished applying changes! :) Please let me know what you think about the |
|
This looks basically ready to go. The one thing I'd still recommend (but not insist on, if you disagree) is making the "public" methods
If you do agree that it can safely be another method of |
|
Also, PRs like this are a testament to both your own excellent work and Julia's amazing composability: if you deleted all the documentation (no, please don't!) this is a remarkably small PR given the huge gain in functionality. Pretty incredible. |
- adds method to `flamegraph()` constructor: `flamegraph(::Timing)`
Fix up docstrings; remove resolved TODO
|
Thanks @timholy for the kind words! ❤️ Agreed regarding how amazing it is that we could add such interesting functionality in such small PRs. 😊 Per your suggestion, I've changed to implement I believe this is ready for final review! |
timholy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge at will!
Co-authored-by: Tim Holy <tim.holy@gmail.com>
|
😁 Thanks! :) I don't have merge permissions, so...... Merge at will! 😁 |
You should have gotten an email about this earlier today...let me know if you can't find it and I'll try to resend. |
|
Hehe oh, you're right! 😁 Thanks! :) Amazing. Really appreciate it! ✔️ 🥳 Do you have any preference regarding Merge vs Squash? I'm inclined to Squash because there were a lot of commits here. |
|
Oh, also, I guess I should do a version bump here. Is this a minor or patch change? (Or major?) I'm inclined to say minor? And do you think it's okay to release both |
|
Yes to squash, yes to minor bump, yes to bringing both new pieces of functionality out in a single release. Before registering, we might want to work on the Documenter docs a bit to advertise this functionality. |
|
I was going to let you do the honors, @NHDaly, but I'm eager to use this. Thanks again! |
|
Hehe, eep! I'm sorry -- I was excited to do the honors, too, but I felt like it probably needs more documentation, and then I got carried away doing some analyses now that we have these tools instead of writing the docs! 🙈 Thanks for the merge, @timholy! :) I'll try to follow up with docs soon! <3 |
|
I may be able to help too. Lots going on so it will be a bit back-burner but it's already helping, so let's at least work with it in master. |

This builds on JuliaLang/julia#37749 to expose the information through SnoopCompile.
This adds a macro to SnoopCompileCore
@snoopi_deepwhich collects deep timings from Julia's type inference, and adds functions to display the resulting information as a profile.TODO:
InferenceFrameInfoin juliaThis is a second attempt at #138.