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

wilkinsona opened this issue Apr 5, 2019 · 1 comment


Copy link

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.


This comment has been minimized.

Copy link

commented Apr 5, 2019

Relates to #22563.

@sdeleuze sdeleuze closed this in fc9ce7c Apr 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.