Repository navigation
Conversation
| continue; | ||
| } | ||
|
|
||
| $queue[] = $this->reflectionProvider->getClass($ancestorName); |
There was a problem hiding this comment.
I think this method could just return an array of BetterReflection's ReflectionClass, no need to convert back again to ClassReflection?
Additionally, there might be more paths in the code that are just interested in parent class names essentially, without the need for any extra work that ClassReflection is doing when resolving ancestors. Try to look for these paths and try to convert them too, measure whether the performance and/or memory consumption improves.
There was a problem hiding this comment.
Done, getDeclaringClasses() now walks and returns BetterReflection's ReflectionClass.
Agent looked for other paths that only need the names: The only one that runs on every analysis is ValueDependencyCollector::noteClassDependency(), which calls getAncestors() just for the names. I timed that loop on a cold self-analysis of phpstan-src: 336,519 calls take 0.39 s summed over all 9 processes, in a 54 s run. So there's nothing to gain there. It also isn't a free swap: getAncestors() creates the ClassReflection of every ancestor, which is what records their missing parents through recordMissingAncestors(). I left it as is.
The rest are cold paths: the purity lookup in PhpClassReflectionExtension::createMethod(), ExtensionClassHelper, and the array_keys($classReflection->getInterfaces()) loops in four Rules/Api rules. I didn't convert them because I wouldn't be able to measure a difference. Happy to do it if you want them anyway
As suggested in the issue,
ClassResultCacheValueExtension::getValue()no longer callsClassReflection::getAncestors(), which resolves the@extends/@implementsPHPDocs and so reachesStubPhpDocProvider. It now walks the parents, interfaces and traits on BetterReflection'sReflectionClass.I compared the walk with
getAncestors()for every class in the classmap. It never finds fewer classes. It only finds more in invalid hierarchies, like a class implementing a trait or an enum.Covered by
e2e/bug-15375and a stub files extension inClassResultCacheValueExtensionTestthat always throws.This PR was AI generated, but reviewed by me.
Closes phpstan/phpstan#15375