-
Notifications
You must be signed in to change notification settings - Fork 133
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
DirectoriesSourceLocator is too ineffective #612
Comments
Probably best to deprecate the This is more of a documentation issue: we have better source locators using different lookups strategies, which are a better fit for most codebases. |
Note: pushing memoization into existing locators is a no-go: it is not their responsibility, and it will lead to a crazy amount of complexity and state-related bugs. Similar to class/function/constant reflectors, a uniform cache/registry design is needed. |
PHPStan's use-case is that DirectorySourceLocator is used for analysed paths. It's possible there's no other way to analyse them, there might not be any other way to discover the analysed symbols. This is how the whole chain of source locators is constructed in PHPStan: https://github.com/phpstan/phpstan-src/blob/master/src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php#L101-L147 |
I'm OK with that, I'm saying that using alternative implementations using different strategies (new code) is preferable to adapting the pre-existing one 👍 Effectively, the pattern is always the same: if you have "seen" something, even if not interesting, you want to keep it memoized for later. We need a decent design for that, which works at the core of the library 👍 |
IMO related to #615 I find that the current approach of "build an AST Locator from a |
Closing here: IMO, the |
What it currently does from my testing:
When asked about an identifier, it parses all sources it can access until the identifier is found, then returns the result.
When asked about another identifier, it parses all sources again it can access... Rinse and repeat.
Ideally, it should first index all identifiers it knows about to be more effective. It's still too resource-intensive to parse all source files, more lazy evaluation would be more welcome.
What I do in my forked implementation that works quite well (https://github.com/phpstan/phpstan-src/blob/master/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php) is:
function
in the regex, the cache is also polluted with class methods which I filter later.My implementation intentionally doesn't care about constants, it would complicate it. And it's only about a single directory, not directories.
The text was updated successfully, but these errors were encountered: