Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/http: optimize some io.Copy calls by reusing buffers
Optimize two calls of io.Copy which cannot make use of neither io.ReaderFrom nor io.WriterTo optimization tricks by replacing them with io.CopyBuffer with reusable buffers. First is fallback call to io.Copy when server misses the optimized case of using sendfile to copy from a regular file to net.TCPConn; second is use of io.Copy on piped reader/writer when handler implementation uses http.CloseNotifier interface. One of the notable users of http.CloseNotifier is httputil.ReverseProxy. benchmark old ns/op new ns/op delta BenchmarkCloseNotifier-4 309591 303388 -2.00% benchmark old allocs new allocs delta BenchmarkCloseNotifier-4 50 49 -2.00% benchmark old bytes new bytes delta BenchmarkCloseNotifier-4 36168 3140 -91.32% Fixes #12455 Change-Id: I512e6aa2f1aeed2ed00246afb3350c819b65b87e Reviewed-on: https://go-review.googlesource.com/14177 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
- Loading branch information