Skip to content

perf(ci): each test shard collects only its own test files - #3810

Merged
dan-petty merged 2 commits into
mainfrom
perf/2371-shard-own-test-files
Nov 6, 2026
Merged

dan-petty merged 2 commits into
mainfrom
perf/2371-shard-own-test-files

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Each test shard now passes the paths of its own test files to pytest. Before, pytest-split chose the tests after collection, so each of the 16 xdist workers collected the whole suite and then dropped three quarters of it. That collection was 13.5% of the CPU time of a full run.

The split is by lines of test code, heaviest file first, and it stores no data. A new test module joins a shard with no other step. The pytest-split dependency is removed. docs/TESTING.md, docs/SDLC.md and the ci-test-shards spec say how the split works.

Closes #2371

Change: openspec/changes/archive/2026-11-06-2371-measure-and-cut-what-each-of/

@dan-petty dan-petty added type/infra Type infra: the build, CI, images or cluster scope/ci GitHub Actions workflows, pre-commit hooks, CI gates, and runners labels Nov 6, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Evidence for #2371.

Premise (in the archived proposal, section Feasibility): pytest-split picks the tests of a shard in pytest_collection_modifyitems, after collection, so every xdist worker collects the whole suite. One full run on a 16-CPU host (2026-11-05) spent 31.8 s of CPU per worker in collection, 13.5% of the CPU of the run. A preload fixture gave 0%.

Checks run on this branch (base c714551152d3, which is origin/main; no rebase was needed):

  • uv run pytest tests/commands/test_ci_shard.py: 16 passed.
  • Pre-push hook (fast static checks and workflow checks): passed.
  • uv run devops ci fail-to-pass --base origin/main: the changed test module errors at collection on base, because it imports _shard_test_files, which base lacks. The command wants a failure in the call phase, so it reports 0 failed. This is a performance change, not a defect fix, so the rule for a fail-to-pass run does not apply in full. The new tests do fail on base.

A shard passes the paths of its own test modules to pytest, so no xdist worker collects the whole suite. The modules go to the shards by lines of test code, heaviest first, with no stored data. The pytest-split dependency is removed.

Plans: openspec/changes/2371-measure-and-cut-what-each-of
@dan-petty
dan-petty force-pushed the perf/2371-shard-own-test-files branch from 409d027 to 050c922 Compare November 6, 2026 17:37
@dan-petty
dan-petty marked this pull request as ready for review November 6, 2026 17:47
@dan-petty

Copy link
Copy Markdown
Owner Author

Update after the first CI run (two failures, both from this change, both fixed):

  • Static Analysis, test-tree: tests/commands/test_ci_shard.py read its own __file__. It now uses tests.support.paths.REPO_ROOT.
  • Tests & Coverage (shard 2 of 4): tests/ui/conftest.py imported devops-cli at its top. A run that names a file below tests/ui/ loads that conftest before the root conftest isolates HOME, so CONFIG_PATH bound to the controller HOME and tests/review/test_review_untrusted_tree.py failed (15 errors). I reproduced it locally with one tests/ui file plus that review file (15 errors), and with the fix both run clean (46 passed with the shard tests). The imports now sit in the fixtures, and docs/TESTING.md states the rule.

The branch was rebased onto origin/main at e999bfe5 with no conflicts. The fixes are squashed into the implementation commit, so the archive commit is last. After the push all checks pass, and the pull request is ready.

@dan-petty
dan-petty merged commit cc189ed into main Nov 6, 2026
24 checks passed
@dan-petty
dan-petty deleted the perf/2371-shard-own-test-files branch November 6, 2026 17:49
dan-petty pushed a commit that referenced this pull request Nov 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.70.2](v0.70.1...v0.70.2)
(2026-11-06)


### Performance Improvements

* **ci:** each test shard collects only its own test files
([#3810](#3810))
([cc189ed](cc189ed))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/ci GitHub Actions workflows, pre-commit hooks, CI gates, and runners type/infra Type infra: the build, CI, images or cluster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(ci): each test shard collects only its own test files

1 participant