When using the reactive webclient with default headers (and cookies) AND headers (and cookies) specified at the request level, there is an additional intermediate map created prior to copying to the final ClientRequest. I believe this can be eliminated in the changes proposed here.
Here is part of the icicle graph of memory allocations:
The stuff done in the middle section should go away and be done on the right. Additionally, the fixes in https://github.com/spring-projects/spring-framework/pull/29972 will improve the forEach and ReadOnlyHttpHeaders performance.
The final copy into the ClientRequest used addAll
but I used putAll
on the defaults and request-provided values in order to preserve the order of operations. Since it appears that nothing else is setting the headers/cookies on that ClientRequest.Builder using add vs put should not matter.
Comment From: rstoyanchev
Thanks for the suggestion. I have added an extra small refactoring, eliminating the intermediate HttpRequest
passed into DefaultResponseSpec
and passing the HttpMethod and URI instead since that's all that was needed.
Comment From: yuzawa-san
@rstoyanchev thank you, could you please consider the sibling PR to this one https://github.com/spring-projects/spring-framework/pull/29972? that one has more performance gains.