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
Lazy create ClassReflection in enum-cases #3059
Conversation
d189b8b
to
5a15a02
Compare
src/Type/Enum/EnumCaseObjectType.php
Outdated
@@ -79,7 +79,7 @@ public function isSuperTypeOf(Type $type): TrinaryLogic | |||
return $type->isSubTypeOf($this); | |||
} | |||
|
|||
$parent = new parent($this->getClassName(), $this->getSubtractedType(), $this->getClassReflection()); | |||
$parent = new parent($this->getClassName(), $this->getSubtractedType()); |
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.
The problem with this is loss of precision. ObjectType often has ClassReflection given be the current scope. It makes analysis more precise if there are multiple classes with the same name - it's going to use reflection from the current file for real.
I have an idea: use classReflection if it's been set but don't fetch it from ReflectionProvider.
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.
it seems we are missing test-coverage for the case you mentioned.
just added a new method to get but not create the class-reflection of the base-class
Is it still faster than before? |
hmm .. you are right.. the perf benefit nearly went away with the lastest change. it seems EnumCaseObjectType is slower when the class-reflection is known. since the perf benefit is not that much, I think we can stop here. |
the enum-case object will lazy create the class-reflection when used the first time.
in our slow repro case this means we don't need to create class-reflection for millions of objects over and over, since we are only check
isSuperTypeOf
.refs phpstan/phpstan#10979
before this PR
after this PR:
not perfect yet, but still good progress