Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Dec 19, 2025

In the profiles of #4628 (comment) we can see MutatingScope->createConditionalExpressions as one of the most expensive calls (which gets called via MutatingScope->merge()):

grafik

After this PR, we can see PHPSTAN_FNSR=1 php bin/phpstan analyse src/Analyser/NodeScopeResolver.php -vvv --debug taking the return $this; fast path ~180 times.

It seems make test is 0.5-1 second faster

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.

WDYT?

public function mergeWith(?self $otherScope): self
{
if ($otherScope === null) {
if ($otherScope === null || $this === $otherScope) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ($otherScope === null || $this === $otherScope) {
if ($otherScope === null || $this === $otherScope || $this->equals($otherScope)) {

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 suggested change will make the test-suite fail with


There was 1 failure:

1) PHPStan\Analyser\NodeScopeResolverTest::testFile with data set "tests/PHPStan/Analyser/nsrt/unset-conditional-expressions.php" ('/Users/staabm/workspace/phpst...ns.php')
Failed assertions in /Users/staabm/workspace/phpstan-src/tests/PHPStan/Analyser/nsrt/unset-conditional-expressions.php:

Line 27:
Expected: array<string, mixed>
Actual:   array{}

/Users/staabm/workspace/phpstan-src/tests/PHPStan/Analyser/NodeScopeResolverTest.php:298

@ondrejmirtes
Copy link
Member

Sounds like something to fix. The equals method should probably also check conditionalExpressions property.

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