Skip to content

Prevent double normalization of FuncCall nodes#4637

Merged
ondrejmirtes merged 1 commit intophpstan:2.1.xfrom
staabm:less-work
Dec 19, 2025
Merged

Prevent double normalization of FuncCall nodes#4637
ondrejmirtes merged 1 commit intophpstan:2.1.xfrom
staabm:less-work

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Dec 19, 2025

In the profiles of #4628 (comment) we can see getDynamicFunctionReturnType as one of the most expensive calls:

grafik

in the happy path in which FuncCall has a Name before this PR we tend to normalize the argument list twice.

this PR remove duplicate arg normalization per FuncCall. I did not send it against fnsr-storage-branch, as I think it will not conflict with the PRs changes and makes sense on its own

if ($normalizedNode !== null && $functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) {
$functionReflection = $this->reflectionProvider->getFunction($functionName, $this);
$resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $node, $functionReflection);
$resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection);
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.

in this path we invoked getDynamicFunctionReturnType without beeing normalized beforehand.

Comment on lines -2474 to +2475
$resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $normalizedNode, $functionReflection);
$resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection);
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.

in this path $node was already normalized in line 2449 and before this PR will get normalized again within getDynamicFunctionReturnType

@ondrejmirtes ondrejmirtes merged commit a09ac35 into phpstan:2.1.x Dec 19, 2025
626 of 634 checks passed
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

@staabm staabm deleted the less-work branch December 19, 2025 09:59
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