-
Notifications
You must be signed in to change notification settings - Fork 38.5k
TypeMappedAnnotation.getValue(int,boolean,boolean) burns a lot of CPU, 2x total CPU usage on process after upgrade from 5.1 to 5.2 #24961
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
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(). Closes gh-24970
Big thanks @sbrannen for looking at this But, the lesson we take away from it at my company is not to have this many request-params on a GET request just because the verb is semantically more correct. A POST with a body is A LOT more efficient CPU/speed-wise in spring. |
I've marked this issue as superseded by #24970.
You're welcome.
Great. Very glad to hear that. And... thank for providing the feedback!
We are indeed considering other ways to improve the performance of our annotation processing.
Any time you have that many request parameters in a single controller method it's good to investigate whether it would be better to bind them all to a single "command object" ( |
See #24981 |
Affects: 5.2
Type: Bug
SpringFramework 5.2 has a regression in CPU performance when dealing with
RequestParameter
s with default values in combination with having aFilter
that looks at theHttpServletRequest
&HttpServletResponse
(AccessLogging). The impact on CPU is massive when upgrading from5.1
to5.2
.I replicated the behaviour here
https://github.com/jensim/spring-boot-compare-22-21
@philwebb
@jhoeller
@sbrannen
The text was updated successfully, but these errors were encountered: