spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Optimize Request Predicate attribute merging

Open poutsma opened this issue 1 year ago • 3 comments

When using router functions, the bulk of RequestPredicate execution is spent in attribute map merging. We should consider ways to improve this, for instance by using composite maps instead of allocating new ones.

poutsma avatar Feb 12 '24 10:02 poutsma

https://github.com/spring-projects/spring-framework/blob/6e9607ce999a01c942551f2d0c85107aa1d4f94b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunctions.java#L1247

https://github.com/spring-projects/spring-framework/blob/6e9607ce999a01c942551f2d0c85107aa1d4f94b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunctions.java#L1267-L1269

What an interesting issue! I think we can use some CompositeMap instead of UnmodifiableMap & deep copy on every withAttributes() on AttributesRouterFunction. (I'm not sure above is what this issue wants)

I fixed similar issue on another opensource before, so if you busy I can create PR :) thank you!

injae-kim avatar Feb 14 '24 10:02 injae-kim

@injae-kim There are a lot of intrinsic details that can go wrong here, which has caused many regressions in the past. So I'd rather tackle this one myself, thanks!

poutsma avatar Feb 14 '24 11:02 poutsma

which has caused many regressions in the past.

Aha thanks for the explanation! I got it. Please share on this issue if there's something I can help 😃

injae-kim avatar Feb 14 '24 13:02 injae-kim