Cache ast-parsing in RegexGroupParser#4655
Conversation
ondrejmirtes
left a comment
There was a problem hiding this comment.
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: