Skip to content

Commit

Permalink
perf: speed up python tracer with frame.f_trace_lines = False (#1381)
Browse files Browse the repository at this point in the history
use the python >= 3.7 feature of being able to disable line tracing by
setting the frame attribute f_trace_lines to False. This can be used for
the frames of functions that we aren't collecting coverage information
for (eg those functions in the stdlib).

This speeds up the pure python tracer in CPython by ~9x and in PyPy by
80% on a coverage run of one realistic project that I tried.
  • Loading branch information
cfbolz committed May 28, 2022
1 parent 1087f17 commit 08ec70f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions coverage/pytracer.py
Expand Up @@ -159,6 +159,8 @@ def _trace(self, frame, event, arg_unused):
if tracename not in self.data:
self.data[tracename] = set()
self.cur_file_data = self.data[tracename]
else:
frame.f_trace_lines = False
# The call event is really a "start frame" event, and happens for
# function calls and re-entering generators. The f_lasti field is
# -1 for calls, and a real offset for generators. Use <0 as the
Expand Down

0 comments on commit 08ec70f

Please sign in to comment.