From df43848ffcbb8c3427a28c1f0c6112846959025a Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 27 Nov 2020 13:01:29 -0500 Subject: [PATCH] Dramatically improve `flamegraph(timing)` performance (#158) * 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! :tada: * Add error-handling for malformed Type Tuples that fail to print. This apparently can happen sometimes, see: https://github.com/JuliaLang/julia/issues/38195 --- src/parcel_snoopi_deep.jl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/parcel_snoopi_deep.jl b/src/parcel_snoopi_deep.jl index 3c26fda85..3f8d2130d 100644 --- a/src/parcel_snoopi_deep.jl +++ b/src/parcel_snoopi_deep.jl @@ -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_