Skip to content

Fix slow analysis on return with a big OR condition#5049

Closed
staabm wants to merge 5 commits intophpstan:2.1.xfrom
staabm:bug-14207-2
Closed

Fix slow analysis on return with a big OR condition#5049
staabm wants to merge 5 commits intophpstan:2.1.xfrom
staabm:bug-14207-2

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 26, 2026

Closes phpstan/phpstan#14207

Regression test before PR:

➜  phpstan-src git:(2.1.x) ✗ time vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php  
PHPUnit 11.5.52 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.30
Configuration: /Users/m.staab/dvl/phpstan-src/phpunit.xml
Random Seed:   1772116653

...............................................................  63 / 212 ( 29%)
............................................................... 126 / 212 ( 59%)
............................................................... 189 / 212 ( 89%)
....S..................                                         212 / 212 (100%)

Time: 00:25.512, Memory: 330.50 MB

After PR (equal fast as AnalyserIntegrationTest on 2.1.x):

➜  phpstan-src git:(bug-14207-2) ✗ time vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php  
PHPUnit 11.5.52 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.30
Configuration: /Users/m.staab/dvl/phpstan-src/phpunit.xml
Random Seed:   1772116718

...............................................................  63 / 211 ( 29%)
............................................................... 126 / 211 ( 59%)
......S........................................................ 189 / 211 ( 89%)
......................                                          211 / 211 (100%)

Time: 00:17.420, Memory: 314.50 MB

Wordpress phpstan analyse --debug src/wp-includes/html-api/class-wp-html-processor.php -v before PR:

Elapsed time: 8.61 seconds

after PR:

Elapsed time: 1.69 seconds

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Reuse it for nested BooleanAnd as well

@staabm
Copy link
Contributor Author

staabm commented Feb 26, 2026

Reuse it for nested BooleanAnd as well

I can add a test for bool-AND but I don't think we need the fix for AND, because AND will narrow the type, not widen as OR does (so it will not produce a big union)

@ondrejmirtes
Copy link
Member

Yeah, only if you produce an example with BooleanAnd that’s slow.

: "{$tag_name->namespace} {$tag_name->node_name}";
}

assertType('non-falsy-string|uppercase-string', $tag_name);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this type is not correct, but its a pre-existing unrelated problem: created a separate issue for that

@staabm
Copy link
Contributor Author

staabm commented Feb 26, 2026

the failling tests make me feel the fix is wrong

@staabm staabm closed this Feb 26, 2026
@staabm staabm deleted the bug-14207-2 branch February 27, 2026 08:32
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.

2 participants