Skip to content

Commit 908573c

Browse files
committed
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
1 parent 4e896d1 commit 908573c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/net/http/transfer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ func (t *transferWriter) writeBody(w io.Writer) (err error) {
410410
//
411411
// This function is only intended for use in writeBody.
412412
func (t *transferWriter) doBodyCopy(dst io.Writer, src io.Reader) (n int64, err error) {
413-
n, err = io.Copy(dst, src)
413+
bufp := copyBufPool.Get().(*[]byte)
414+
buf := *bufp
415+
defer copyBufPool.Put(bufp)
416+
417+
n, err = io.CopyBuffer(dst, src, buf)
414418
if err != nil && err != io.EOF {
415419
t.bodyReadError = err
416420
}

0 commit comments

Comments
 (0)