AnnotationUtils performance degrades with deep stacks #32921
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: enhancement
A general enhancement
Milestone
Affects: 5.3.1 +
Profiling of a complex Spring-based web application shows a bottleneck in
AnnotationUtils.getValue()
that cannot be reproduced in JMH benchmarks. Further investigation showed the problem comes from generating deep stack traces in the exception cases (NoSuchMethodException
orThrowable
), and the JMH benchmark uses a very shallow stack (~5) while our application uses a rather deep one (~150). The depth comes largely from nested Tomcat filters, but Spring also contributes.Exception cases primarily result from lookups of
@javax.inject.Qualifier()
and attributevalue
, via the following stack trace:I've attached a speed test that reproduces the exception case, and contains an alternative implementation that is faster in all cases (I think). The test can reproduce different stack depths by changing the value of "stackDepth".
Results from my computer:
AnnotationUtilsSpeedTest.java.txt
The text was updated successfully, but these errors were encountered: