I have HTTP proxy server proxying plain HTTP 1.1 requests based on google/martian. When I profile the memory allocations I see that transferWriter.doBodyCopy() calls io.Copy() resulting in many buffer allocations. The profile graph is attached below.
I think doBodyCopy() could use copyBufPool we have in response.ReadFrom() to avoid the allocations.
The text was updated successfully, but these errors were encountered:
changed the title
net/http: transferWriter.doBodyCopy calls io.Copy reslting Dec 9, 2022
This patch is a followup to 6fd82d8.
It applies copyBufPool optimization to transferWriter.doBodyCopy().
The function is very frequently used - everytime Request or Response is written to a wire.
Without this patch for every Request and Response processed, if there is a body, we need to allocate and GC a 32k buffer.
This is quickly causing GC pressure.