Repository navigation
[perf] Memoize StaticPHPUnitEnvironment::isPHPUnitRun - #8732
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
isPHPUnitRun()answers a per-process constant (PHPUNIT_COMPOSER_INSTALLis 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 fromSkipper::resolveSkippedClasses(), which calls it once per skip resolution. Each call paid adefined()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 seetrueand 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):
Run on both branches to compare: