Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5x Faster IntersectionType->getEnumCases() #3695

Merged
merged 1 commit into from
Nov 30, 2024
Merged

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
@@ -842,7 +842,7 @@ public function getEnumCases(): array
foreach ($this->types as $type) {
$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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants