-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance: Reduce isObjectType calls #3502
Performance: Reduce isObjectType calls #3502
Conversation
@@ -350,7 +355,11 @@ private function isObjectTypeOfObjectType(ObjectType $resolvedObjectType, Object | |||
} | |||
|
|||
$classReflection = $this->reflectionProvider->getClass($resolvedObjectType->getClassName()); | |||
if (\trait_exists($requiredObjectType->getClassName())) { | |||
if (!isset($this->traitExistsCache[$classReflection->getName()])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a follow up for #3501
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you @keulinho 👍
@@ -350,7 +355,11 @@ private function isObjectTypeOfObjectType(ObjectType $resolvedObjectType, Object | |||
} | |||
|
|||
$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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed with #3627
As seen in #3500
isObjectType
-calls can be pretty costly in terms of performance, in a lot of casesisObjectType
was used in combination withisName
in multiple rectors, in those cases checkingisName
first is a lot faster and removes a lot of not needed calls toisObjectType
Together with #3501 this PR leads to the same performance improvements as the original PR #3500