Closed klauer closed 10 months ago
Great catch. Looks like a simple and easy fix.
@Theelx any comments? Otherwise I'll make a patch release ASAP.
Merging #236 (73b8385) into main (17387b3) will not change coverage. The diff coverage is
n/a
.
Looks good to me! Thanks for catching this @klauer!
Thanks for the great tool and the quick response on this, @Theelx and @Erotemic!
Issue
For each call of
get_stats
, the implicit conversion of the C++unordered_mapping
c_code_map
to a Python dict is currently being performedlen(code_hash_map)
-times. In scenarios where a large amount of code is being profiled, this can result in a significant performance penalty.The fix in this PR
Moving the implicit conversion out of the loop and only performing it once is what this PR proposes.
In numbers
In our use case, line-profiler 4.x has been unusable due to this performance hit (which I've only just quantified and narrowed down to this conversion today):
With
len(code_hash_map)
at around 1000, line_profiler main branch shows for me:And with this PR: