Skip to content

Commit 08ec70f

Browse files
authored
perf: speed up python tracer with frame.f_trace_lines = False (#1381)
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.
1 parent 1087f17 commit 08ec70f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

coverage/pytracer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ def _trace(self, frame, event, arg_unused):
159159
if tracename not in self.data:
160160
self.data[tracename] = set()
161161
self.cur_file_data = self.data[tracename]
162+
else:
163+
frame.f_trace_lines = False
162164
# The call event is really a "start frame" event, and happens for
163165
# function calls and re-entering generators. The f_lasti field is
164166
# -1 for calls, and a real offset for generators. Use <0 as the

0 commit comments

Comments
 (0)