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

Avoid SourceClass creation for annotations that are always ignored #22750

Closed
wilkinsona opened this issue Apr 5, 2019 · 1 comment
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Apr 5, 2019

In a small Spring Boot app, ConfigurationClassParser$SourceClass.getAnnotations() creates 200 SourceClass instances each for @Target, @Retention, and @Documented. They are then skipped as they're in a java.* package:

private void collectImports(SourceClass sourceClass, Set<SourceClass> imports, Set<SourceClass> visited)
throws IOException {
if (visited.add(sourceClass)) {
for (SourceClass annotation : sourceClass.getAnnotations()) {
String annName = annotation.getMetadata().getClassName();
if (!annName.startsWith("java") && !annName.equals(Import.class.getName())) {
collectImports(annotation, imports, visited);
}
}
imports.addAll(sourceClass.getAnnotationAttributes(Import.class.getName(), "value"));
}
}

It doesn't take long (a handful of milliseconds), but I still think it would be worth avoiding the unnecessary time that's spent and the unnecessary garbage that's created by changing SourceClass.getAnnotations() to only create SourceClass instances for annotations that are then processed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 5, 2019
@jhoeller jhoeller self-assigned this Apr 5, 2019
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 5, 2019
@jhoeller jhoeller added this to the 5.1.7 milestone Apr 5, 2019
@jhoeller
Copy link
Contributor

jhoeller commented Apr 5, 2019

Relates to #22563.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants