Repository navigation
cache file reporters and analyses for the whole reporting phase - #2215
Merged
Merged
Conversation
_analyze and _get_file_reporter used lru_cache(maxsize=1), which unfortunately doesn't work when reporting sweeps the file list, e.g. pytest-cov's total pass followed by its term report. We now cache them in per-instance dicts instead, clearing whenever measured data changes (flush, load, combine, erase).
Contributor
Author
|
For cryptography, running this on a 4 core Linux VM (5 averaged runs)
(The total pass is done first to do fail under checks, then it produces whatever potential output you might want, e.g. the terminal report, HTML, etc) |
Member
|
This is now released as part of coverage 7.15.1. |
1 task
reaperhulk
pushed a commit
to reaperhulk/coveragepy
that referenced
this pull request
Jul 13, 2026
Version 7.15.1 regressed memory during reporting: the whole-phase caches added in coveragepy#2215 retained every file's FileReporter and Analysis, and each cached PythonFileReporter pinned its parser's AST, so a 1,500-module branch corpus peaked at 555 MB vs 98 MB on 7.15.0. PythonParser now releases its AST once _analyze_ast() has memoized everything derived from it, and the analysis and file reporter caches are bounded with oldest-first eviction, so modest projects keep the full repeated-sweep speedup while large projects get bounded memory; with both changes the corpus peaks at 127 MB. The bound is configurable as the new [report] analysis_cache_size setting or the --analysis-cache-size flag on reporting commands, defaulting to 256 files. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0116eASQSH9ZQ9ZGwXtjobqH
reaperhulk
pushed a commit
to reaperhulk/coveragepy
that referenced
this pull request
Jul 13, 2026
Version 7.15.1 regressed memory during reporting: the whole-phase caches added in coveragepy#2215 retained every file's FileReporter and Analysis, and each cached PythonFileReporter pinned its parser's AST, so a 1,500-module branch corpus peaked at 555 MB vs 98 MB on 7.15.0. PythonParser now releases its AST once _analyze_ast() has memoized everything derived from it, and the analysis and file reporter caches are bounded with oldest-first eviction, so modest projects keep the full repeated-sweep speedup while large projects get bounded memory; with both changes the corpus peaks at 127 MB. The bound is configurable as the new [report] analysis_cache_size setting or the --analysis-cache-size flag on reporting commands, defaulting to 256 files. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0116eASQSH9ZQ9ZGwXtjobqH
reaperhulk
pushed a commit
to reaperhulk/coveragepy
that referenced
this pull request
Jul 13, 2026
Version 7.15.1 regressed memory during reporting: the whole-phase caches added in coveragepy#2215 retained every file's FileReporter and Analysis, and each cached PythonFileReporter pinned its parser's AST, so a 1,500-module branch corpus peaked at 555 MB vs 98 MB on 7.15.0. PythonParser now releases its AST once _analyze_ast() has memoized everything derived from it, and the analysis and file reporter caches are bounded with oldest-first eviction, so modest projects keep the full repeated-sweep speedup while large projects get bounded memory; with both changes the corpus peaks at 127 MB. The bound is configurable as the new [report] analysis_cache_size setting or the COVERAGE_ANALYSIS_CACHE_SIZE environment variable, defaulting to 256 files. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0116eASQSH9ZQ9ZGwXtjobqH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_analyze and _get_file_reporter used lru_cache(maxsize=1), which unfortunately doesn't work when reporting sweeps the file list, e.g. pytest-cov's total pass followed by its term report.
We now cache them in per-instance dicts instead, clearing whenever measured data changes (flush, load, combine, erase).