]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: inline chunkWriter in response
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 28 Mar 2013 20:13:28 +0000 (13:13 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 28 Mar 2013 20:13:28 +0000 (13:13 -0700)
A chunkWriter and a response are 1:1. Make them contiguous in
memory and save an allocation.

benchmark                                   old ns/op    new ns/op    delta
BenchmarkServerFakeConnWithKeepAliveLite        10715        10539   -1.64%

benchmark                                  old allocs   new allocs    delta
BenchmarkServerFakeConnWithKeepAliveLite           21           20   -4.76%

benchmark                                   old bytes    new bytes    delta
BenchmarkServerFakeConnWithKeepAliveLite         1626         1609   -1.05%

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/8114043

src/pkg/net/http/server.go

index 3a0cca7fdc7c4dafa7034b21edc4aeeb213f531d..baddc72bc80f4436d829279b0691bdc5bb1f3481 100644 (file)
@@ -288,7 +288,7 @@ type response struct {
        wroteContinue bool     // 100 Continue response was written
 
        w  *bufio.Writer // buffers output in chunks to chunkWriter
-       cw *chunkWriter
+       cw chunkWriter
        sw *switchWriter // of the bufio.Writer, for return to putBufioWriter
 
        // handlerHeader is the Header that Handlers get access to,
@@ -558,10 +558,9 @@ func (c *conn) readRequest() (w *response, err error) {
                req:           req,
                handlerHeader: make(Header),
                contentLength: -1,
-               cw:            new(chunkWriter),
        }
        w.cw.res = w
-       w.w, w.sw = newBufioWriterSize(w.cw, bufferBeforeChunkingSize)
+       w.w, w.sw = newBufioWriterSize(&w.cw, bufferBeforeChunkingSize)
        return w, nil
 }