Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable line coverage events where not used #4180

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RELEASE_TYPE: patch

Hypothesis collects coverage information during the :ref:`shrinking hypothesis.Phase.shrink` and :ref:`explain hypothesis.Phase.explain` phases in order to show a more informative error message. On 3.12+, this uses :mod:`sys.monitoring`. This patch improves the performance of coverage collection on 3.12+ by disabling events we don't need.
11 changes: 6 additions & 5 deletions hypothesis-python/src/hypothesis/internal/scrutineer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def trace(self, frame, event, arg):
if event == "call":
return self.trace
elif event == "line":
# manual inlining of self.trace_line for performance.
fname = frame.f_code.co_filename
if should_trace_file(fname):
current_location = (fname, frame.f_lineno)
Expand All @@ -87,10 +86,12 @@ def trace(self, frame, event, arg):

def trace_line(self, code: types.CodeType, line_number: int) -> None:
fname = code.co_filename
if should_trace_file(fname):
current_location = (fname, line_number)
self.branches.add((self._previous_location, current_location))
self._previous_location = current_location
if not should_trace_file(fname):
return sys.monitoring.DISABLE

current_location = (fname, line_number)
self.branches.add((self._previous_location, current_location))
self._previous_location = current_location

def __enter__(self):
if not self._should_trace:
Expand Down
Loading