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

FISH-5938 5530 improve cdi scan #5531

Merged
merged 16 commits into from
Jan 28, 2022

Conversation

sgflt
Copy link
Contributor

@sgflt sgflt commented Dec 9, 2021

Fixes #5530

Testing Performed

Deployment of testcase finished in 5 seconds.

sgflt added 9 commits December 9, 2021 20:10
- removed redundant contains on set
- list replaced by set
- exclusions extracted because there is no need to discover the same annotation dozentimes and define it as excluded over and over again
- removed redundant contains on set
- list replaced by set
- exclusions extracted because there is no need to discover the same annotation dozentimes and define it as excluded over and over again
- if the annotation is cdi enabling, then it does not matter whether it is excluded or not
- there we want to list all classes with annotation
- if we exclude some custom annotation then only the first class with that annotation was included
}
for (final AnnotationModel am : type.getAnnotations()) {
final AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at, exclusions) && type.wasDefinedIn(paths)) {
Copy link
Contributor

@svendiedrichsen svendiedrichsen Dec 12, 2021

Choose a reason for hiding this comment

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

Could this be improved by checking type.wasDefinedIn(paths) on the outer if/for? Something like !(type instanceof AnnotationType) && type.wasDefinedIn(paths). This would avoid annotation analysis for some types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see.

@svendiedrichsen
Copy link
Contributor

svendiedrichsen commented Dec 12, 2021

@sgflt Could the prefilled annotation lists be converted to sets? This would speed up contains calls when checking annotation names.

@svendiedrichsen
Copy link
Contributor

svendiedrichsen commented Dec 13, 2021

@sgflt Could the prefilled annotation lists be converted to sets? This would speed up contains calls when checking annotation names.

Sorry for being vague on this and of course it wouldn't be as dramatic an improvement as your changes already are. I'm talking about these:

protected static final List<String> cdiScopeAnnotations
protected static final List<String> cdiEnablingAnnotations
protected static final List<String> excludedAnnotationTypes

If those were Sets it would improve on speed a little bit when checking for a class name being contained. And because they are queried at such a high frequency it could make some noticable difference.

@sgflt sgflt marked this pull request as draft December 14, 2021 06:01
- as they are used for heavy lookups
- this small subset of well known annotations does not solve problem of custom cyclic annotations
  as they are used in kotlin

- f.e. kotlin.Metadata
…otation

- pattern is the same as in isCDIEnablingAnnotation
@@ -403,20 +368,29 @@ private static boolean isCDIEnablingAnnotation(AnnotationType annotationType,
public static boolean hasValidAnnotation(Class annotatedClass,
Copy link
Contributor

@svendiedrichsen svendiedrichsen Dec 14, 2021

Choose a reason for hiding this comment

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

Could this method signature be changed to accept validScopes and excludedScopes as Set<String> painlessly? This would make copying the collections obsolete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are placese where constant fields are passed, so we should not modify them. The copy is done on public api level and collections passed as parameter are only local implementation which is safe to verify their modification.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I see.

@@ -95,8 +97,7 @@ public InjectionServicesImpl(InjectionManager injectionMgr, BundleDescriptor con
* @return
*/
private boolean isInterceptor( Class beanClass ) {
HashSet<String> annos = new HashSet<>();
annos.add( javax.interceptor.Interceptor.class.getName() );
final Set<String> annos = Collections.singleton(javax.interceptor.Interceptor.class.getName());
Copy link
Contributor

@svendiedrichsen svendiedrichsen Dec 14, 2021

Choose a reason for hiding this comment

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

This returns an immutable Set. Is this intentional? If you remove the collection copying from the other method modifications of this set will throw an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I preffer to not modify collections passed as parameter to public API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. Good rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, only validScopes are not modified. There it is possible.

@sgflt sgflt marked this pull request as ready for review December 14, 2021 19:22
@svendiedrichsen
Copy link
Contributor

@sgflt LGTM. Good job.

@breakponchito
Copy link
Contributor

Jenkins test

1 similar comment
@breakponchito
Copy link
Contributor

Jenkins test

@rdebusscher rdebusscher added the PR: CLA CLA submitted on PR by the contributor label Dec 17, 2021
@breakponchito breakponchito self-requested a review January 28, 2022 22:46
Copy link
Contributor

@breakponchito breakponchito left a comment

Choose a reason for hiding this comment

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

LGTM

@breakponchito breakponchito merged commit 556dbad into payara:master Jan 28, 2022
@Pandrex247 Pandrex247 changed the title 5530 improve cdi scan FISH-5938 5530 improve cdi scan Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: CLA CLA submitted on PR by the contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: CDI annotation scanning is very slow /FISH-5938
4 participants