Skip to content

Use per-instance caches in PythonParser - #2214

Merged
nedbat merged 1 commit into
coveragepy:mainfrom
reaperhulk:claude/parser-per-instance-caches
Jul 6, 2026
Merged

nedbat merged 1 commit into
coveragepy:mainfrom
reaperhulk:claude/parser-per-instance-caches

Conversation

@reaperhulk

Copy link
Copy Markdown
Contributor

first_line and exit_counts were cached with functools.lru_cache on the methods. A cache on a method is keyed by (self, args), so it pins the parser instances themselves.

Caching on the instance instead makes reporting on a 99-file corpus 29% faster (1.78s to 1.27s, nearly all of it collector time) and drops live objects after the run from ~387k to ~17k.

first_line and exit_counts were cached with functools.lru_cache on the
methods.  A cache on a method is keyed by (self, args), so it pins the
parser instances themselves.

Caching on the instance instead makes reporting on a 99-file corpus 29%
faster (1.78s to 1.27s, nearly all of it collector time) and drops live
objects after the run from ~387k to ~17k.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019XC1KLKyNuR5dA3YxAkxUC
@nedbat
nedbat merged commit 36a14a0 into coveragepy:main Jul 6, 2026
42 checks passed
@nedbat

nedbat commented Jul 12, 2026

Copy link
Copy Markdown
Member

This is now released as part of coverage 7.15.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants