Skip to content
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

[PropertyInfo] Adds static cache to PhpStanExtractor #54894

Open
wants to merge 7 commits into
base: 7.2
Choose a base branch
from

Conversation

mvhirsch
Copy link
Contributor

@mvhirsch mvhirsch commented May 12, 2024

Q A
Branch? 7.2
Bug fix? no (performance)
New feature? no
Deprecations? no
Issues
License MIT

I was able to detect a performance penalty when using dozens of traits in even more classes. The PhpStanExtractor creates a NameScope every time, but afaik this can be cached like in PhpDocExtractor (see #32188).

The performance impact is impressive, as it reduces the time needed for my TestCase by 30%. See Blackfire profile comparison.

@derrabus
Copy link
Member

Please target 7.1. We usually don't merge performance improvements into LTS branches.

@derrabus derrabus modified the milestones: 6.4, 7.1 May 13, 2024
@xabbuh
Copy link
Member

xabbuh commented May 15, 2024

Shouldn't we now also implement the ResetInterface to prevent memory leaks?

@xabbuh xabbuh removed this from the 7.1 milestone May 15, 2024
@xabbuh xabbuh added this to the 7.2 milestone May 15, 2024
@mvhirsch
Copy link
Contributor Author

Shouldn't we now also implement the ResetInterface to prevent memory leaks?

If so, the PhpDocExtractor should implement it too, I guess.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 17, 2024

implement the ResetInterface to prevent memory leaks?

If all we store is class metadata, we don't need a reset IMHO as the leak is upper bounded, and resetting might effect performance of long running kernels for little memory savings in the end.

if (null === $docNode) {
return null;
}

$nameScope = $this->contexts[$class.$declaringClass] ??= $this->nameScopeFactory->create($class, $declaringClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$nameScope = $this->contexts[$class.$declaringClass] ??= $this->nameScopeFactory->create($class, $declaringClass);
$nameScope = $this->contexts[$class.'/'.$declaringClass] ??= $this->nameScopeFactory->create($class, $declaringClass);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to move this inside the loop, right before the nested foreach?:

$nameScope ??= $this->contexts[$class.'/'.$declaringClass] ??= $this->nameScopeFactory->create($class, $declaringClass);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to move this inside the loop, right before the nested foreach?:

You mean here?

Sounds reasonable to me. It may make sense to skip creating one unless really needed (and since my change is all about re-using a created one, it hardly influences performance).

Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants