Skip to content

Faster NullableType resolving#2870

Closed
staabm wants to merge 2 commits intophpstan:1.10.xfrom
staabm:nullable
Closed

Faster NullableType resolving#2870
staabm wants to merge 2 commits intophpstan:1.10.xfrom
staabm:nullable

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Jan 14, 2024

running phpstan on microsoft/microsoft-graph shows a bottleneck on TypeCombinator::addNull in ParserNodeTypeToPHPStanType->resolve.

grafik

since we are in a very low level method we can just return new UnionType and prevent calls to isSuperTypeOf and union which shaves of a few seconds

@ondrejmirtes
Copy link
Copy Markdown
Member

You can't do this for some types, for example ?mixed. Yeah the type is wrong but it'd break something down the line in PHPStan.

@staabm staabm closed this Jan 14, 2024
@staabm staabm deleted the nullable branch January 14, 2024 10:21
@ondrejmirtes
Copy link
Copy Markdown
Member

Looks like the method is called a lot of times. The number of times should correspond to the number of functions/methods inside the project. Maybe the type could be cached in reflection layer in more places.

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Jan 14, 2024

Looks like the method is called a lot of times. The number of times should correspond to the number of functions/methods inside the project.

the method is called once per parameter and once per return type. so it is called way more often then methods/functions contained in the project beeing scanned.

@ondrejmirtes
Copy link
Copy Markdown
Member

Yeah that's what I meant of course, but we should verify it's not called more often (I suspect it is, definitely for closures and arrow functions, maybe even normal functions and methods).

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