mirror of
https://github.com/golang/go
synced 2024-11-26 10:58:16 -07:00
net/http: use copyBufPool in transferWriter.doBodyCopy()
This is a followup to CL 14177. It applies copyBufPool optimization to
transferWriter.doBodyCopy(). The function is used every time Request or
Response is written.
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.
Fixes #57202
Change-Id: I4c30e1737726ac8d9937846106efd02effbae300
GitHub-Last-Rev: 908573cdbe
GitHub-Pull-Request: golang/go#57205
Reviewed-on: https://go-review.googlesource.com/c/go/+/456435
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
This commit is contained in:
parent
3128aeec87
commit
96eeb4512b
@ -410,7 +410,11 @@ func (t *transferWriter) writeBody(w io.Writer) (err error) {
|
||||
//
|
||||
// This function is only intended for use in writeBody.
|
||||
func (t *transferWriter) doBodyCopy(dst io.Writer, src io.Reader) (n int64, err error) {
|
||||
n, err = io.Copy(dst, src)
|
||||
bufp := copyBufPool.Get().(*[]byte)
|
||||
buf := *bufp
|
||||
defer copyBufPool.Put(bufp)
|
||||
|
||||
n, err = io.CopyBuffer(dst, src, buf)
|
||||
if err != nil && err != io.EOF {
|
||||
t.bodyReadError = err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user