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

Pointcut compilation #346

Merged
merged 5 commits into from
Jul 24, 2024
Merged

Conversation

jlabedo
Copy link
Contributor

@jlabedo jlabedo commented Jul 22, 2024

Description

Compile pointcuts during compilation phase.
Pointcuts are tested on a lot of different classes during compilation phase, so this PR may speed compilation phase of large projects.
For a medium sized project with Symfony, I obtained merely 10% performance boost on cache:clear.

(also made some cleaning, droping the dependency on InterfaceToCallRegistry for pointcuts. This could have a bad impact on performance as no reflection cache is used, but it required adding the registry to each MethodInterceptor::create calls)

Type of change

  • Performance

return new PointcutRegexExpression($token);
}
if (TypeDescriptor::isItTypeOfExistingClassOrInterface($token)) {
$classDefinition = ClassDefinition::createFor(TypeDescriptor::create($token));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the actual implementation, the interface registry is used here.

Copy link
Member

Choose a reason for hiding this comment

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

What about using InterfaceToCallRegistry::getClassDefinitionFor?

From the PR I understood that intention to not use this is related to code visibility.
But ClassDefinition::createFor is not cached, therefore it will be resolved separately per each Pointcut.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the compilation is done during pointcut creation (Pointcut::createWith) and the registry is needed during compilation.
I had 3 possibilities:

  • no cahing :)
  • injecting InterfaceToCallRegistry on Pointcut::createWith but not sure it is always available, and it is called in a lot of places, I did not want to pollute the review of the PR.
  • delaying compilation on first call to Pointcut::doesItCut, but in that case invalid pointcuts can be created without throwing and I have to change some tests.

What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be interesting to have the registry at construction time also here:

if (! ClassDefinition::createFor($type)->isAnnotation()) {

Copy link
Member

Choose a reason for hiding this comment

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

injecting InterfaceToCallRegistry on Pointcut::createWith but not sure it is always available, and it is called in a lot of places, I did not want to pollute the review of the PR.

This is how we do it with other components, but I see your point about amount of extra work.
Anyways not a blocker for this one, as seems that this PR actually bring performance improvement even without caching.
Let's go without the cache then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is ok for the amount of extra work, it was for clarity for the reviewer :) I may add this in another PR.

return new PointcutRegexExpression($token);
}
if (TypeDescriptor::isItTypeOfExistingClassOrInterface($token)) {
$classDefinition = ClassDefinition::createFor(TypeDescriptor::create($token));
Copy link
Member

Choose a reason for hiding this comment

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

What about using InterfaceToCallRegistry::getClassDefinitionFor?

From the PR I understood that intention to not use this is related to code visibility.
But ClassDefinition::createFor is not cached, therefore it will be resolved separately per each Pointcut.

@jlabedo jlabedo merged commit 8f0a101 into ecotoneframework:main Jul 24, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants