Skip to content

[perf] Memoize StaticPHPUnitEnvironment::isPHPUnitRun - #8732

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-memoize-isphpunitrun
Oct 20, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-memoize-isphpunitrun

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

isPHPUnitRun() answers a per-process constant (PHPUNIT_COMPOSER_INSTALL is defined once at phpunit bootstrap and never changes), yet it is called hundreds of thousands of times per run - an in-process profile of 120 rector-src files records ~255k calls, most of them from Skipper::resolveSkippedClasses(), which calls it once per skip resolution. Each call paid a defined() lookup.

Memoized into a static ?bool. Behaviour is unchanged: the constant is already defined before the first call in a test process, so tests still see true and the Skipper test-mode cache reset still fires.

Micro A/B (bench/phpunit_env_bench.php, 255k calls x 200 repeats, PHP 8.4, CPU user+sys):

  • before: cpu 7.16s
  • after: cpu 5.45s (~24% faster per call)

Run on both branches to compare:

php bench/phpunit_env_bench.php

@TomasVotruba
TomasVotruba merged commit f1849fb into main Oct 20, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-memoize-isphpunitrun branch October 20, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant