Skip to content

Prevent TypeCombinator::intersect() calls in MutatingScope-> specifyExpressionType()#5048

Merged
ondrejmirtes merged 5 commits intophpstan:2.1.xfrom
staabm:less-specify
Feb 26, 2026
Merged

Prevent TypeCombinator::intersect() calls in MutatingScope-> specifyExpressionType()#5048
ondrejmirtes merged 5 commits intophpstan:2.1.xfrom
staabm:less-specify

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 26, 2026

running phpstan analyse --debug src/ on Wordpress:

before this PR:
TypeCombinator::intersect invoked 37100x
after this PR:
TypeCombinator::intersect invoked 1146x

saves 3-5 seconds which translates to a 2-3% perf improvement


TypeCombinator::intersect is the most expensive part of MutatingScope-> specifyExpressionType() in WP:

grafik

requires https://github.com/phpstan/phpstan-src/pull/5047/files

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@staabm staabm changed the base branch from 2.2.x to 2.1.x February 26, 2026 09:04
@ondrejmirtes
Copy link
Member

Oh nice, can't wait to merge this!

@clxmstaab clxmstaab force-pushed the less-specify branch 2 times, most recently from bbc187b to 94008eb Compare February 26, 2026 10:34
@staabm staabm marked this pull request as ready for review February 26, 2026 10:54
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

$reportUnmatched = (bool) ($uniquedExpandedIgnoreErrors[$key]['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors);
if (!$reportUnmatched) {
$reportUnmatched = $ignoreError['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors;
}
Copy link
Member

Choose a reason for hiding this comment

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

How does this change relate to the rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the previous expression

($uniquedExpandedIgnoreErrors[$key]['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors) || ($ignoreError['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors)

errored with

Only booleans are allowed in ||, mixed given on the right side.

@ondrejmirtes ondrejmirtes merged commit c5bfadb into phpstan:2.1.x Feb 26, 2026
639 of 649 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