Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Nov 30, 2024

refs phpstan/phpstan#11968

using a reduced repro

before this PR

➜ phpstan-src git:(2.0.x) ✗ hyperfine 'php bin/phpstan analyze test11968.php --debug' -i Benchmark 1: php bin/phpstan analyze test11968.php --debug Time (mean ± σ): 9.262 s ± 0.039 s [User: 9.106 s, System: 0.153 s] Range (min … max): 9.192 s … 9.326 s 10 runs 

after this PR

➜ phpstan-src git:(2.0.x) ✗ hyperfine 'php bin/phpstan analyze test11968.php --debug' -i Benchmark 1: php bin/phpstan analyze test11968.php --debug Time (mean ± σ): 1.755 s ± 0.005 s [User: 1.636 s, System: 0.117 s] Range (min … max): 1.745 s … 1.762 s 10 runs 

the full repro of phpstan/phpstan#11968 takes still 11,5 seconds after this PR on my m4 pro (took 1min10s before)

@staabm staabm changed the title 5x Faster IntersectionType-> getEnumCases() 5x Faster IntersectionType->getEnumCases() Nov 30, 2024
$oneType = [];
foreach ($type->getEnumCases() as $enumCase) {
$oneType[md5($enumCase->describe(VerbosityLevel::typeOnly()))] = $enumCase;
$oneType[$enumCase->getClassName() . '::' . $enumCase->getEnumCaseName()] = $enumCase;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since we only handle enum case objects here, which are always final, we should be able to take this shortcut

@staabm staabm marked this pull request as ready for review November 30, 2024 13:56
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 48f8990 into phpstan:1.12.x Nov 30, 2024
453 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants