Improved resource usage when invoke RequestMappingInfoHandlerMapping.handleNoMatch #29611
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: superseded
An issue that has been superseded by another
RequestMappingInfoHandlerMapping
handleNoMatch()
method has the following format.https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java#L246
https://github.com/spring-projects/spring-framework/blob/main/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java#L169
And this method may allow an empty value in
Set<RequestMappingInfo> infos
parameter.(Unfortunately, it happens a lot in the service I am running.)
The constructor code of org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping.PartialMatchHelper is shown below.
https://github.com/spring-projects/spring-framework/blob/main/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java#L227
This code executes follwoing method even if there is no value in infos
java.util.Collection#stream
java.util.stream.Collectors#toList
java.util.stream.ReferencePipeline#collect(java.util.stream.Collector<? super P_OUT,A,R>)
Unnecessary resources are used via these methods.(create objects and execute operations, so )
Even though parameters have values, it seems better not to use Stream.
It can save resources by changing the constructor like mvc's RequestMappingInfoHandlerMapping.
https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java#L300
Below is a test created similar to the code above.
Result (from Async Profiler)
In my opinion, the following order seems like a good way.
(Suggested solution (3 + 2) -> 3 -> 2 -> 1)
I will make PR according to your opinion.
Thanks :)
The text was updated successfully, but these errors were encountered: