-
Notifications
You must be signed in to change notification settings - Fork 547
Cache ast-parsing in RegexGroupParser #4655
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
Conversation
ondrejmirtes
left a comment
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.
What about caching one step sooner on $regex?
|
Running NodeScopeResolverTest is not representative of usual PHPStan analysis performance, because no rules are running. So it's still valuable to have faster tests but saying we need to optimize TypeTraverser might not be true. |
|
I'm currently running |
|
Thank you! |
|
Here it is: https://blackfire.io/profiles/194a65b8-7351-443e-be57-9c936cd6d985/graph 11.6% spent in TypeCombinator::union(), 21.5% spent in resolveType. TypeTraverser is "only" 6.04 %. 2 % of that is resolveLateResolvableTypes which might still be useful to optimize/call less often. |
looking at the expressions beeing resolved, we can see the following counts: measured using diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php
index be05271cf1..fddabb6513 100644
--- a/src/Analyser/MutatingScope.php
+++ b/src/Analyser/MutatingScope.php
@@ -921,6 +921,15 @@ class MutatingScope implements Scope, NodeCallbackInvoker
private function resolveType(string $exprString, Expr $node): Type
{
+ static $types = [];
+ if ($types === []) {
+ register_shutdown_function(function() use (&$types) {
+ var_dump($types);
+ });
+ }
+ $types[get_class($node)] ??= 0;
+ $types[get_class($node)] ++;
+
foreach ($this->expressionTypeResolverExtensionRegistry->getExtensions() as $extension) { |
before this PR:
after this PR:
after this PR the runtime of
NodeScopeResolverTestis now dominated byTypeTraverserandTypeCombinator: