-
Notifications
You must be signed in to change notification settings - Fork 478
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
Memoize expensive calls to docComments. #458
Conversation
e23f3d0
to
f8aef12
Compare
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.
Hi, this looks promising, thanks!
src/Reflection/ClassReflection.php
Outdated
@@ -933,7 +936,7 @@ public function getResolvedPhpDoc(): ?ResolvedPhpDocBlock | |||
return null; | |||
} | |||
|
|||
$docComment = $this->reflection->getDocComment(); | |||
$docComment = $this->reflectionDocComment ?? $this->reflectionDocComment = $this->reflection->getDocComment(); |
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.
I'd like to use a control structure (an if
) here instead of just ??
on a single line. Like this:
if ($this->reflectionDocComment !== null) {
$docComment = $this->reflectionDocComment;
} else {
$docComment = $this->reflection->getDocComment();
$this->reflectionDocComment = $docComment;
}
src/Type/FileTypeMapper.php
Outdated
@@ -518,7 +521,8 @@ private function getPhpDocKey( | |||
string $docComment | |||
): string | |||
{ | |||
$docComment = \Nette\Utils\Strings::replace($docComment, '#\s+#', ' '); | |||
$cacheKey = md5($docComment); | |||
$docComment = $this->docKeys[$cacheKey] ?? $this->docKeys[$cacheKey] = \Nette\Utils\Strings::replace($docComment, '#\s+#', ' '); |
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.
And the same here.
This reduces both RAM consumption & execution time.
f8aef12
to
0329dfd
Compare
@ondrejmirtes thanks for your feedback! Can you please look at it again? I don't understand why some tests fail. I'm not sure it is related to my changes... Can you please advise? |
Master is broken, it's not your fault 😊 |
Thank you! |
I ran multiple tests using Blackfire. Memoizing these expensive calls reduces both RAM consumption & execution time.
This is an example with running on https://github.com/pyguerder/phpstan-propel2-example/blob/master/generated-classes/App/AnalyzeMe2.php only: https://blackfire.io/profiles/compare/7f25525d-0676-40b8-a809-a92692106be6/graph
And this is an example running on my main project (154 classes): https://blackfire.io/profiles/compare/7cc0ea82-3727-4a95-b948-112678bc0991/graph
@ondrejmirtes can you please have a look at this?
Thanks in advance, best regards