From e4ffd6535c7418459ab05a235a78c4eb9200f514 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Thu, 20 Aug 2026 00:23:56 -0700 Subject: [PATCH] perf(ci): measure unit-shard coverage with the sys.monitoring core 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. --- .github/workflows/_test-unit-base.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/_test-unit-base.yml b/.github/workflows/_test-unit-base.yml index 4f4339a360a6..54f50524a391 100644 --- a/.github/workflows/_test-unit-base.yml +++ b/.github/workflows/_test-unit-base.yml @@ -129,6 +129,13 @@ jobs: WORKERS: ${{ inputs.workers }} RERUNS: ${{ inputs.reruns }} DIST: ${{ inputs.dist }} + # coverage.py's sys.monitoring backend (PEP 669), the cheapest core it has. + # It is only the default from Python 3.14, and these shards run 3.12, so it + # has to be asked for. Coverage refuses it when branch measurement is on + # (`branch_right_left` needs > 3.14.0a5) and falls back to the slow core with + # a `no-sysmon` warning, so turning on `branch = true` here means giving this + # back until the runners move to 3.14. + COVERAGE_CORE: sysmon run: | if [ "${WORKERS}" = "0" ]; then uv run --no-sync pytest ${TEST_PATH:?} \