Skip to content

Fix slow enum-union with lots of cases#2985

Merged
ondrejmirtes merged 4 commits intophpstan:1.10.xfrom
staabm:fix
Mar 22, 2024
Merged

Fix slow enum-union with lots of cases#2985
ondrejmirtes merged 4 commits intophpstan:1.10.xfrom
staabm:fix

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Mar 22, 2024

closes phpstan/phpstan#10772

this effectively reverts 0a39b42 but fixes a nasty perf problem

the reproducer of #10772 took >2 minutes before this change and finishes instantly after it

$ time ../phpstan-src/bin/phpstan analyse --debug
Note: Using configuration file C:\dvl\Workspace\stan-long\phpstan.neon.
C:\dvl\Workspace\stan-long\src\test.php


 [OK] No errors



real    0m2.669s
user    0m0.000s
sys     0m0.000s

Todo: regression test

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Mar 22, 2024

Todo: regression test

not sure where to put the regression test, since we need a composer.json/lock. in the past we used AnalyzerIntegration test, but this doesn't have composer.json project level.

should I do a end-2-end test? if so, how/where to put a "timeout" for it?


alternatively I can try to reduce the existing test to something without external composer dependencies

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Mar 22, 2024

(added regression test)

if ($types[$i] instanceof StringType && !$types[$i] instanceof ClassStringType) {
$hasGenericScalarTypes[ConstantStringType::class] = true;
}
$enumCases = $types[$i]->getEnumCases();
Copy link
Copy Markdown
Contributor

@VincentLanglet VincentLanglet Mar 22, 2024

Choose a reason for hiding this comment

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

If the issue is with getEnumCases be slow.

Shouldn't be introduced a new method isSomething, implemented by all types in order to avoid the error message

Doing instanceof PHPStan\\\\Type\\\\Enum\\\\EnumCaseObjectType is error\\-prone and deprecated\\

?

Then

if ($types[$i]->isSomething()->yes()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure its worth a new type-method just for this bottleneck

@ondrejmirtes ondrejmirtes merged commit 944673f into phpstan:1.10.x Mar 22, 2024
@ondrejmirtes
Copy link
Copy Markdown
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