Skip to content

perf: the tests run in parallel, only the affected tests run locally, and CI runs in shards - #1750

Draft
dsebastien wants to merge 8 commits into
mainfrom
perf/1740-faster-tests
Draft

dsebastien wants to merge 8 commits into
mainfrom
perf/1740-faster-tests

Conversation

@dsebastien

@dsebastien dsebastien commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Closes #1740.

The back-end tests were the slowest step of every change. This pull request makes each test cheaper, runs the suite in parallel by default, gives a builder a command that runs only the tests of a change, and splits CI into jobs that run at the same time.

What changes

  1. tools/test/run.sh: Pest in parallel (three quarters of the CPUs, TEST_PROCESSES changes it), with Xdebug and PCOV off and the opcode cache of the command line (tools/test/php/tests.ini, added with PHP_INI_SCAN_DIR so that every worker gets it). composer test uses it.
  2. tools/test/affected.sh [base] (default origin/main): all of tests/Unit, the feature tests that read the files of the tree, then the tests of the changed files with the native test impact analysis of Pest 5 (--tia --filtered, a coverage map recorded with PCOV). A change to Composer, config/, routes/, migrations, providers, bootstrap/ or the test setup runs the full suite. composer test:affected uses it.
  3. OpenApiDocumentTest: one export of the document for the file, not one per test (69 s to 4 s).
  4. CI: four jobs at the same time: Static checks, Front-end, Back-end tests (1/3), (2/3), (3/3) (time-balanced with tests/.pest/shards.json), and main, which waits for all of them. PHP runs with coverage: none. Pint reads only the PHP files of the pull request (all files when pint.json or composer.lock changes). A test slower than 10 s gets a warning, and the slowest tests go to the summary of the run.
  5. tools/merge/gate-merge.sh polls until no check is pending (60 s, 90 min at most) and reads the required checks from the branch protection.
  6. AGENTS.md, CONTRIBUTING.md, tools/README.md: a builder runs tools/test/affected.sh; the pull request runs the full suite.

Numbers

Measured on 2026-11-24 and 2026-11-25 in the development container (12 CPUs), with the load next to each number, while other work ran on the machine. The final numbers on an idle machine come later.

Run Before After
Sample: tests/Unit and 20 feature files (726 tests), 4 processes 131 s, 125 s (load 3.7 to 5.1) 40 s, 50 s, 52 s (load 4.0 to 6.1)
Full suite (5 176 tests), 4 processes 309 s (load 7.3 to 7.9); 237 s with the OpenAPI change (load 1.4 to 5.7)
CI of a pull request (workflow CI) 36 min (one job: tests 18 min, Pint 3 min) 3 min 45 s (the longest job, Front-end, 3 min 38 s; each test shard 2 min 30 s to 2 min 43 s, its tests 92 to 101 s; formatting 13 s; PHPStan 11 s)

What each setting gives on the sample (726 tests, 4 processes): Xdebug off 128 s to 68 s; PCOV off 68 s to 62 s; the opcode cache 62 s to 52 s.

Measured and left out

  1. Schema dump: migrate:fresh takes 3 s once per worker process (not per test); a dump saves under 2 % of a run and adds a psql version dependency in CI.
  2. RefreshDatabase already uses one transaction per test after that first migration; the boot of the application takes 13 ms per test with the opcode cache. A lighter base for tests without a table gains little.

Required checks

The required check main keeps its name: it is now the job that waits for the others. The new checks are Static checks, Front-end, Back-end tests (1/3), Back-end tests (2/3) and Back-end tests (3/3). No change to the branch protection is needed.

Commits

  1. fix(build): the merge gate waits until no check is pending.
  2. perf(qa): tools/test/run.sh and tools/test/php/tests.ini (parallel, no Xdebug, no PCOV, the opcode cache), composer test.
  3. perf(qa): one OpenAPI export for OpenApiDocumentTest.
  4. perf(qa): tools/test/affected.sh, composer test:affected.
  5. perf(qa): tests/.pest/shards.json and tools/test/slow-tests.php.
  6. ci: the parallel jobs and the 3 shards.
  7. docs: AGENTS.md, CONTRIBUTING.md, tools/README.md, documentation/conventions/rules.md.

Commands of a builder

  1. docker compose exec -T -u sail laravel.test bash tools/test/affected.sh [base] while working (default base origin/main).
  2. docker compose exec -T -u sail laravel.test bash tools/test/run.sh [Pest arguments] for the whole suite or a part of it (TEST_PROCESSES=4 for fewer processes).

What is left

  1. The clean numbers on an idle machine: a full tools/test/run.sh with the default processes (9 of 12 CPUs), to write in CONTRIBUTING.md (target: under 3 minutes).
  2. A full check of tools/test/affected.sh: its first two parts ran (git in a worktree inside the container, tests/Unit and 14 feature files: 939 tests in 27 s, load about 5). The first --tia run, which records the map with PCOV, was stopped before its end; a second run that replays the map is not checked yet.
  3. No container restart is needed: every setting is in the command.

Questions for the owner

  1. Three shards of 4 processes use 5 runners for each push of a pull request (with Static checks, Front-end and main). Keep 3 shards? Recommended: yes; the free runners of a public repository are enough, and 2 shards would make the back-end jobs about 1 minute longer than Front-end.
  2. The new concurrency of the workflow CI stops the run of an older push of the same pull request. Keep it? Recommended: yes.

gh pr checks --watch can return while a long job is still pending, and the
merge was then lost. The script now polls every 60 seconds, for 90 minutes at
most, until no check is pending and every required check is there. It reads
the required checks from the branch protection of main, else from one list.
It still merges only when every check is green.
tools/test/run.sh runs Pest in parallel (three quarters of the CPUs by
default, TEST_PROCESSES changes it), with XDEBUG_MODE=off, PCOV off and
the opcode cache of the command line. PHP_INI_SCAN_DIR adds the settings
of tools/test/php/tests.ini, so every worker process gets them.

On a sample of 726 tests (4 processes, load 4 to 6): 125 to 131 s with
the settings of the container, 40 to 52 s with these (#1740).
The document comes from the code only, and each of the 20 tests exported
it again (3 s each): the file took 69 s, now 4 s (#1740).
tools/test/affected.sh [base] runs all of tests/Unit and the feature
tests that read the files of the tree, then the tests of the changed
files with the test impact analysis of Pest (--tia --filtered). A change
to Composer, the configuration, the routes, the migrations, the service
providers or the test setup runs the full suite (#1740).
…the slow tests

tests/.pest/shards.json lets Pest give each CI shard about the same
time. tools/test/slow-tests.php warns for each test slower than 10 s
and writes the slowest tests to the summary of the run (#1740).
The one job of 35 minutes becomes: the static checks, the front-end, and
the back-end tests in 3 shards of 4 processes, at the same time. PHP runs
without a coverage driver. Pint checks only the PHP files of the pull
request (every file when pint.json or composer.lock changes): it took
3 minutes for 1 084 files. The job main waits for every job, so the
required check keeps its name (#1740).
A builder runs tools/test/affected.sh; the pull request runs the full
suite in CI (#1740).

This branch has not been deployed

No deployments
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.

The back-end tests are too slow: 7 to 39 minutes locally, 25 minutes in CI

1 participant