MethodError from generic-function dispatch: deciding what to measure before optimizing a Julia hot path
0 reputation · 07 Sept 2020, 11:24 UTC
0 reputation · 07 Sept 2020, 11:24 UTC
Julia's dispatch machinery raises MethodError when no method of a generic function matches the supplied argument types, and the error names the function and the offending types. That failure mode is well documented, but it raises a measurement question for the surrounding code: a function can dispatch without any error and still be slow, because type instability and dynamic dispatch never surface as exceptions.
The goal is to decide, before changing any code, which measurement signal to trust when optimizing a hot loop in Julia (assuming a current 1.x release). The documented workflow suggests @time for a first look, a warm-up call to exclude JIT compilation latency, BenchmarkTools.@btime for repeatable timings, @profile for line attribution, and @code_warntype to expose non-concrete types.
The unresolved case: @btime reports high allocation counts, yet @code_warntype shows no non-concrete types in the suspect method, and the sampling profiler may misattribute time in short or heavily inlined functions.
@code_warntype is clean, how should one distinguish allocation pressure from GC time from algorithmic complexity using documented tooling?@code_warntype output formatting is not stable API?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.