Performance: Reduce isObjectType calls#3502
Merged
samsonasik merged 1 commit intorectorphp:mainfrom Mar 22, 2023
Merged
Conversation
keulinho
commented
Mar 22, 2023
|
|
||
| $classReflection = $this->reflectionProvider->getClass($resolvedObjectType->getClassName()); | ||
| if (\trait_exists($requiredObjectType->getClassName())) { | ||
| if (!isset($this->traitExistsCache[$classReflection->getName()])) { |
samsonasik
approved these changes
Mar 22, 2023
Member
samsonasik
left a comment
There was a problem hiding this comment.
Looks good, thank you @keulinho 👍
staabm
reviewed
Apr 17, 2023
| $classReflection = $this->reflectionProvider->getClass($resolvedObjectType->getClassName()); | ||
| if (\trait_exists($requiredObjectType->getClassName())) { | ||
| if (!isset($this->traitExistsCache[$classReflection->getName()])) { | ||
| $this->traitExistsCache[$classReflection->getName()] = \trait_exists($requiredObjectType->getClassName()); |
Contributor
There was a problem hiding this comment.
calling trait_exists or any other runtime autoloading mechanism like class_exists in a static analysis context with phpstan is wrong most of the time.
these *_exists calls will trigger the real autoloader and might lead to code beeing executed. this in turn can have side effects which can lead to different analysis results based on the order in which files are analyzed.
on the long run, rector should not use *_exists php-src functions at all.
in phpstan you ususally use the *Reflection apis which use static reflection, which in turns makes sure that no code is beeing executed while analysis.
samsonasik
pushed a commit
that referenced
this pull request
May 8, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As seen in #3500
isObjectType-calls can be pretty costly in terms of performance, in a lot of casesisObjectTypewas used in combination withisNamein multiple rectors, in those cases checkingisNamefirst is a lot faster and removes a lot of not needed calls toisObjectTypeTogether with #3501 this PR leads to the same performance improvements as the original PR #3500