Skip to content

Commit

Permalink
Dramatically improve flamegraph(timing) performance (#158)
Browse files Browse the repository at this point in the history
* Dramatically improve `flamegraph(timing)` performance

Move method instance's specTypes Type Tuple from a compile-time argument
to a runtime argument, to prevent compiling a specialization for every
_value_ in the data!

I hadn't meant to write it that way in the first place, I had just done
it absent-mindedly, because `specTypes` is a Type, so I hadn't thought
about moving it back into the value domain.

We used `@snoopi_deep` to find out the problem and fix this performance
problem! It's neat to see it profiling itself! 🎉

* Add error-handling for malformed Type Tuples that fail to print.

This apparently can happen sometimes, see:
JuliaLang/julia#38195
  • Loading branch information
NHDaly authored Nov 27, 2020
1 parent cc016af commit df43848
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/parcel_snoopi_deep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,17 @@ function frame_name(mi::Core.Compiler.MethodInstance)
return frame_name(m.name, mi.specTypes)
end
# Special printing for Type Tuples so they're less ugly in the FlameGraph
function frame_name(name, ::Type{TT}) where TT<:Tuple
io = IOBuffer()
Base.show_tuple_as_call(io, name, TT)
v = String(take!(io))
return v
function frame_name(name, @nospecialize(tt::Type{<:Tuple}))
try
io = IOBuffer()
Base.show_tuple_as_call(io, name, tt)
v = String(take!(io))
return v
catch e
e isa InterruptException && rethrow()
@warn "Error displaying frame: $e"
return name
end
end

# NOTE: The "root" node doesn't cover the whole profile, because it's only the _complement_
Expand Down

0 comments on commit df43848

Please sign in to comment.