You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reintroduce synthesized annotation attribute value caching
Prior to the introduction of the MergedAnnotation API in Spring Framework
5.2, our SynthesizedAnnotationInvocationHandler utilized a cache for
annotation attribute values; whereas, the new
SynthesizedMergedAnnotationInvocationHandler has no such caching in
place.
Issues such as gh-24961 indicate a regression in performance caused by
the lack of such an attribute value cache. For example, the required
attribute in @RequestParam is looked up using the internal meta-model
in the MergedAnnotation API twice per request for each @RequestParam in
a given controller handler method.
This commit reintroduces the attribute value cache to avoid the
unnecessary performance overhead associated with multiple lookups of
the same attribute in a synthesized annotation. This applies not only
to direct attribute method invocations but also to invocations of
equals() and hashCode() on a synthesized annotation.
Note, however, that this commit does NOT address multiple lookups of
annotation attribute values for invocations of toString(). That behavior
currently remains unchanged in the implementation of
org.springframework.core.annotation.TypeMappedAnnotation.toString().
Closesgh-24970
Copy file name to clipboardExpand all lines: spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java
+53-5Lines changed: 53 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,14 @@
18
18
19
19
importjava.lang.annotation.Annotation;
20
20
importjava.lang.reflect.AnnotatedElement;
21
+
importjava.lang.reflect.Array;
21
22
importjava.lang.reflect.InvocationHandler;
22
23
importjava.lang.reflect.Method;
23
24
importjava.lang.reflect.Proxy;
24
25
importjava.util.Arrays;
26
+
importjava.util.Map;
25
27
importjava.util.NoSuchElementException;
28
+
importjava.util.concurrent.ConcurrentHashMap;
26
29
27
30
importorg.springframework.lang.Nullable;
28
31
importorg.springframework.util.Assert;
@@ -50,6 +53,8 @@ final class SynthesizedMergedAnnotationInvocationHandler<A extends Annotation> i
0 commit comments