Repository navigation
Commit c3dde4f
authored
Speed up WordPress PHPUnit tests (#619)
## Summary
The WordPress PHPUnit job takes about 10 minutes, and most of that time
is PHPUnit itself. This PR speeds it up with two small changes that only
affect the tests:
- **Turn off PHP's garbage collector for PHPUnit.** While tests run, PHP
keeps searching a large amount of memory for objects it can free, and it
rarely finds much. In a short-lived test process, this isn't worth the
time.
- **Use the low bcrypt cost in class fixtures too.**
`WP_UnitTestCase::set_up()` lowers the bcrypt cost for each test, but
`wpSetUpBeforeClass()` runs before it. Users created there still hash
passwords at PHP's default cost, and those hashes took most of the time
spent in class fixtures.
Test order and the list of expected failures stay unchanged.
**Memory use goes up.** A full WordPress PHPUnit run now peaks at about
4.2 GB instead of about 0.5 GB. This fits the 16 GB CI runner, but a
local Docker setup needs that much memory available for a full run. The
WordPress test bootstrap already removes the PHP memory limit, so no new
limit setting is needed. The SQLite plugin suites use the same command
and use very little memory either way.
The bcrypt issue is in WordPress's own test code, so it could also be
fixed there. Until then, `wp-setup.sh` adds the filter, as it already
does for other test changes.
## Why
PHPUnit takes about 7.5 minutes of the job on slower runners, and the
job is by far the slowest one in CI. Profiling showed that the SQLite
database itself is under 5% of that time, so these changes target where
the time actually goes.
## Measured speedups
**On CI:** GitHub-hosted runners vary a lot in speed, so each run is
compared with baseline runs on a runner of similar speed. As in #579,
the webpack build time from the same job shows the runner's speed. The
baseline is 14 recent runs without this change, 12 of which match these
two speeds.
| Runner | Baseline PHPUnit | This PR | Change | PHPUnit ÷ build time |
Whole job |
| --- | ---: | ---: | ---: | ---: | ---: |
| Slower (build about 14s) | 464s (10 runs) |
[286s](https://github.com/WordPress/sqlite-database-integration/actions/runs/42244888948/attempts/3)
| **~38% faster** | 32.9 → 21.2 | ~10m50s → 7m35s |
| Faster (build about 9s) | 311s (2 runs) |
[172s](https://github.com/WordPress/sqlite-database-integration/actions/runs/42244888948/attempts/2)
| **~45% faster** | 35.8 → 19.0 | ~7m30s → 5m13s |
These are two runs of this PR, one on each runner speed. Test results
match the baseline runs: 30,900 tests, with the same errors and
failures, and the expected failures check passes. Peak memory went from
515 MB to 4.18 GB.
**Locally:** the full suite on native PHP 8.3 (not Docker), in seconds.
Each row adds to the one above it. The list of failing tests was
identical in all three runs.
| Mode | PHPUnit | Change |
| --- | ---: | ---: |
| Current settings | 197.7s | — |
| Garbage collector off | 153.8s | **~22% faster** |
| Garbage collector off and low bcrypt cost in fixtures | 126.6s |
**~36% faster** |
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Chores**
* Updated PHP test execution settings and WordPress test setup. These
changes affect the project’s testing configuration; no end-user-facing
changes are included.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 586046e commit c3dde4f
2 files changed
Lines changed: 18 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
66 | 80 | | |
67 | 81 | | |
68 | 82 | | |
69 | | - | |
| 83 | + | |
70 | 84 | | |
71 | 85 | | |
72 | 86 | | |
73 | | - | |
| 87 | + | |
74 | 88 | | |
75 | 89 | | |
76 | 90 | | |
0 commit comments