Skip to content

Commit 4b592fe

Browse files
committed
perf: set frame->f_trace_lines=0 when not tracing. ~3% faster
1 parent 6503308 commit 4b592fe

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

coverage/ctracer/tracer.c

+1
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
514514
Py_XDECREF(self->pcur_entry->file_data);
515515
self->pcur_entry->file_data = NULL;
516516
self->pcur_entry->file_tracer = Py_None;
517+
frame->f_trace_lines = 0;
517518
SHOWLOG(PyFrame_GetLineNumber(frame), filename, "skipped");
518519
}
519520

coverage/pytracer.py

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def _trace(self, frame, event, arg_unused):
161161
self.cur_file_data = self.data[tracename]
162162
else:
163163
frame.f_trace_lines = False
164+
164165
# The call event is really a "start frame" event, and happens for
165166
# function calls and re-entering generators. The f_lasti field is
166167
# -1 for calls, and a real offset for generators. Use <0 as the
@@ -176,6 +177,7 @@ def _trace(self, frame, event, arg_unused):
176177
self.last_line = -frame.f_code.co_firstlineno
177178
else:
178179
self.last_line = frame.f_lineno
180+
179181
elif event == 'line':
180182
# Record an executed line.
181183
if self.cur_file_data is not None:
@@ -186,6 +188,7 @@ def _trace(self, frame, event, arg_unused):
186188
else:
187189
self.cur_file_data.add(lineno)
188190
self.last_line = lineno
191+
189192
elif event == 'return':
190193
if self.trace_arcs and self.cur_file_data:
191194
# Record an arc leaving the function, but beware that a
@@ -213,6 +216,7 @@ def _trace(self, frame, event, arg_unused):
213216
if real_return:
214217
first = frame.f_code.co_firstlineno
215218
self.cur_file_data.add((self.last_line, -first))
219+
216220
# Leaving this function, pop the filename stack.
217221
self.cur_file_data, self.cur_file_name, self.last_line, self.started_context = (
218222
self.data_stack.pop()

lab/benchmark.py

+21-30
Original file line numberDiff line numberDiff line change
@@ -257,44 +257,35 @@ def run_experiments(
257257

258258
run_experiments(
259259
py_versions=[
260+
Python(3, 7),
260261
Python(3, 10),
261262
],
262263
cov_versions=[
263264
("none", None, None),
264265
("6.4", "coverage==6.4", ""),
265-
("6.4 timid", "coverage==6.4", "timid=True"),
266-
(
267-
"PR 1381",
268-
"git+https://github.com/cfbolz/coveragepy.git@f_trace_lines",
269-
"",
270-
),
271-
(
272-
"PR 1381 timid",
273-
"git+https://github.com/cfbolz/coveragepy.git@f_trace_lines",
274-
"timid=True",
275-
),
266+
("tip", "-e ~/coverage/trunk", ""),
276267
],
277268
projects=[
278269
PytestHtml(),
279270
],
280-
num_runs=3,
271+
num_runs=5,
281272
)
282273

283-
run_experiments(
284-
py_versions=[
285-
PyPy(3, 9),
286-
],
287-
cov_versions=[
288-
("none", None, None),
289-
("6.4", "coverage==6.4", ""),
290-
(
291-
"PR 1381",
292-
"git+https://github.com/cfbolz/coveragepy.git@f_trace_lines",
293-
"",
294-
),
295-
],
296-
projects=[
297-
PytestHtml(),
298-
],
299-
num_runs=3,
300-
)
274+
# run_experiments(
275+
# py_versions=[
276+
# PyPy(3, 9),
277+
# ],
278+
# cov_versions=[
279+
# ("none", None, None),
280+
# ("6.4", "coverage==6.4", ""),
281+
# (
282+
# "PR 1381",
283+
# "git+https://github.com/cfbolz/coveragepy.git@f_trace_lines",
284+
# "",
285+
# ),
286+
# ],
287+
# projects=[
288+
# PytestHtml(),
289+
# ],
290+
# num_runs=3,
291+
# )

0 commit comments

Comments
 (0)