perf(ci): measure unit-shard coverage with the sys.monitoring core - #37589
Conversation
Coverage is the single biggest time lever on the unit shards: the legacy
no-coverage workflow ran the same directory in about 5 minutes against 11 to 13
with coverage on. coverage.py's sys.monitoring backend (PEP 669) is the cheapest
core it ships, and it is not in use here today.
It has to be asked for explicitly. coverage 7.14 only defaults to sysmon from
Python 3.14 (`SYSMON_DEFAULT = CPYTHON and PYVERSION >= (3, 14)`) and these
shards pin 3.12, so without `COVERAGE_CORE` they get the slow tracer.
The audit left open whether sysmon survives turning on branch coverage. It does
not, at this Python. coverage gates branch measurement under sysmon on
`branch_right_left`, which needs newer than 3.14.0a5; on 3.12 it refuses and
falls back to the default core with a `no-sysmon` warning. Verified directly
against Python 3.12.13 with coverage 7.14.0:
$ COVERAGE_CORE=sysmon python -m coverage run --branch --source=. run.py
CoverageWarning: Can't use core=sysmon: sys.monitoring can't measure
branches in this version, using default core (no-sysmon)
So this speedup and `branch = true` are mutually exclusive until the runners
move to 3.14. Nothing here turns branch coverage on, so the two never collide
in this change, but whoever does turn it on is choosing to give this back.
Greptile SummaryThe PR configures unit-test coverage to use coverage.py’s
Confidence Score: 5/5The PR appears safe to merge with the current Python 3.12 and coverage 7.14.0 unit-shard configuration. All callers use Python 3.12, both pytest branches collect coverage, and the active coverage configuration does not enable branch measurement or another option that would prevent use of the sysmon core.
|
| Filename | Overview |
|---|---|
| .github/workflows/_test-unit-base.yml | Selects the sysmon coverage core for all unit shards; current Python, coverage version, commands, and coverage configuration are compatible. |
Reviews (1): Last reviewed commit: "perf(ci): measure unit-shard coverage wi..." | Re-trigger Greptile
|
Measured on CI rather than a laptop: pytest's own wall time on the budgets shard goes 432s to 48s with 38 passed on both sides, proxy-utils 429s to 49s with 200 passed. Setup did not change. Numbers for four shards are in the description. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
tin-berri
left a comment
There was a problem hiding this comment.
Switches coverage measurement to sys.monitoring (PEP 669) instead of the settrace tracer via COVERAGE_CORE=sysmon — 1-line env var change, well-proven: confirmed sysmon isn't the 3.12 default, confirmed it's silently incompatible with branch coverage (documented, not silently broken), and measured a real 47-89% pytest-step speedup across 4 shards with identical test counts on both sides (isolated via step-level timing showing setup didn't change, only the test step did). Minimal, well-justified infra change. CI green.
TLDR
Problem this solves:
How it solves it:
branch = truecannot both be onUser Flow
Before: a contributor waits on a required check that is spending much of its time in coverage bookkeeping
proxy-infra / Run tests, takes about 15 minutesAfter: the same check measures the same lines through the cheapest core coverage.py ships
COVERAGE_CORE=sysmon, so coverage.py drives PEP 669sys.monitoringinstead of the settrace tracer--cov=./litellminvocationRelevant issues
Linear ticket
Pre-Submission checklist
uv run pytest tests/test_litellm/<your_test_file>.py -vScreenshots / Proof of Fix
Two things need proving: that asking for sysmon is not a no-op at this Python, and that it cannot be combined with branch coverage. Both are shown against the exact versions CI pins, Python 3.12 and coverage 7.14.0. The wall-clock effect is measured by this pull request's own shard run, since a laptop under other load cannot produce a number worth quoting.
Shared setup:
Before (5290150)
coverage does not choose sysmon on its own at 3.12
After (e4ffd65)
Asking for sysmon works, and is silent
Asking for sysmon together with branch coverage is refused
This is the open question answered: the two are mutually exclusive until the runners move to Python 3.14. Nothing in this change turns branch coverage on.
Wall clock, this run against #37586
#37586 is the same tree on the same day with no coverage-core change, so its shards are the baseline. Comparing whole-job durations would be misleading, since a job also pays for checkout, dependency install and Prisma generation, so the numbers below are pytest's own reported wall time from each job's log, and each row states the test counts on both sides to show the same work was done.
Same counts on both sides of every row, so this is the same work measured twice.
budgetsshard:Setup did not get faster, it got slightly slower. The whole difference is the test step.
The size of the gain tracks how much work each test does rather than how many tests there are:
budgetsruns 38 tests in what was seven minutes, and it drops about 89%, whileAll Other Providersruns 7,742 fast tests and drops about 47%. Shards dominated by heavy execution under the tracer are the ones that were paying most for it.Type
🚄 Infrastructure
Caveats
branch = trueon 3.12; that trade is now documentedFinal Attestation