Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
net/http: consider reusing buffers replacing io.Copy calls with io.CopyBuffer #12455
As been shown in #12450 by crude patch to make io.Copy reuse its underlying 32k buffer(s) workloads intensively (ab)using net/http can see a significant reduce in GC pressure. Since changes to io.Copy has already been proposed and rejected, I'd like to discuss the prospect of replacing at least some of the io.Copy calls in net/http by io.CopyBuffer with reused byte slices.
The net/http uses io.Copy the most in standard library, and I believe updating it to use recently introduced io.CopyBuffer is worth doing.
At least some of those calls are not subject to usual io.ReaderFrom/io.WriterTo optimizations.
I'm ready to implement changes in the upcoming days and propose a CL.
@bradfitz one candidate is fallback path in net/http.response.ReadFrom, another is io.Copy used on liveSwitchReader when one makes use of http.CloseNotifier — httputil.ReverseProxy would gain most benefit from this.