Description
Nick Hristov opened SPR-17307 and commented
org.springframework.context.event.AbstractApplicationEventMulticaster.ListenerRetriever#getApplicationListeners
method performs an unnecessary sort:
It creates a list which is a combination of this.applicationListeners
and this.applicationListenerBeans
and sorts that list. However, the sorting is unnecessary if either one of the two collections is empty. Furthermore, due to the fact that the sorting utilizes the reflection lookups, this sort can become an expensive unnecessary overhead in some use cases.
In my case, I load large amounts of data (> 1K of objects) via Spring Data Mongo which fires off events for every object loaded in the system.
So the sort operation ends up taking about 38% of the overall cost of the processing, more than any other component in my use case.
Affects: 5.0.5
Attachments:
- Screen Shot 2018-09-26 at 8.36.54 PM.png (413.86 kB)
Issue Links:
- Improve performance by maintaining sort of application listeners [SPR-17308] #21841 Improve performance by maintaining sort of application listeners ("is duplicated by")
- Cache order result per Class in OrderUtils (for AnnotationAwareOrderComparator) [SPR-17064] #21602 Cache order result per Class in OrderUtils (for AnnotationAwareOrderComparator)
- ApplicationListener is missing from Collection returned by getApplicationListeners() if it was added after the multicaster was initialised [SPR-17324] #21858 ApplicationListener is missing from Collection returned by getApplicationListeners() if it was added after the multicaster was initialised
- Request backport of SPR-17307 [SPR-17349] #21883 Request backport of SPR-17307
Backported to: 5.0.10