-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Avoid unnecessary synthesizable annotation processing [SPR-16933] #21472
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
Comments
Phil Webb commented Looking at the profiler, |
Phil Webb commented Updating the sample to just get immediate annotations and only once per class gives 32ms public static void main(String[] args) throws ClassNotFoundException {
LogFactory.getLog(TimeMe2.class);
Set<String> names = new HashSet<>(Arrays.asList(NAMES));
long t = System.nanoTime();
for (String name : names) {
Class.forName(name).getAnnotations();
}
System.err.println(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t));
} |
Juergen Hoeller commented Phil Webb, since there seem to be some immediate optimizations that we can apply to |
Juergen Hoeller commented I've done a revision on master which considers any I'll backport a variant of this to 5.0.9, being less aggressive with exclusion and primarily focused on avoiding |
Juergen Hoeller commented Slightly extended scope again: We're avoiding synthesizable annotation creation for |
Sam Brannen commented Thanks for tackling all of this, Juergen Hoeller! |
Juergen Hoeller commented For 5.1, we also cache declared annotation arrays now, avoiding GC pressure for the reflection-returned array clones. Last but not least, |
fbutter commented Juergen Hoeller, in this commit a condition was added to exclude beans without a Component annotation. Consequently beans provided by bean methods are not considered as listener anymore. This is a major change and e.g. spring cloud is not compatible anymore (spring-cloud-consul-discovery is not compatible with Spring Boot 2.1.1.RELEASE #481|https://github.com/spring-cloud/spring-cloud-consul/issues/481]). I could not find this in the release notes, was this intended? |
For the record, the |
I just got bitten by this change... in an event listener in our own test suite, where the package is |
Phil Webb opened SPR-16933 and commented
I've been looking at the performance involved with using the
SimpleMetadataReader
and I suspect that it might be possible to improveAnnotationUtils
.I started with the following application that simulates the class parsing involved in a typical Spring Boot application
https://gist.github.com/philwebb/a22ea7bf5b575abd058a748fe12838d0
This app takes about 130ms to read the metadata from those 106 classes.
If I change the code to use an empty ASM visitor, parsing takes ~30ms
Reading just class bytes into an array takes ~22ms (so ASM parsing itself is quite fast)
If I remove the code that visits annotations so no
AnnotationAttributes
are read, it takes ~60ms.Looking at the profiler a lot of time is spent in
AnnotationUtils
so I created a second sample:https://gist.github.com/philwebb/f7cdc99401af8e063853b2ed574e9277
The
NAMES
being used here are the same as were ultimately used with the first sample. This one is reading annotation data for 413 classes (starting from their String name) and it takes ~93ms.Affects: 5.0.7
Attachments:
Issue Links:
@EventListener
@Scheduled
task runs twice on bean with target-class scoped proxy (when injected)0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: