Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: don't create io.LimitedReaders for 0 byte GET requests #5188

Closed
bradfitz opened this issue Apr 3, 2013 · 2 comments
Closed

net/http: don't create io.LimitedReaders for 0 byte GET requests #5188

bradfitz opened this issue Apr 3, 2013 · 2 comments

Comments

@bradfitz
Copy link
Contributor

bradfitz commented Apr 3, 2013

When the net/http server receives a GET request, it calls io.LimitedReader(r, 0) which
allocates an *io.LimitedReader just to read 0 bytes.

The package already contains an eofReader global variable to return 0 bytes.

Further, no need to io.Copy(ioutil.Discard, ...) from it, since it's empty, and we know
that.

This saves one allocation per GET request.

benchmark                         old ns/op    new ns/op    delta
BenchmarkServerHandlerTypeLen         13888        13279   -4.39%
BenchmarkServerHandlerNoLen           12912        12229   -5.29%
BenchmarkServerHandlerNoType          13348        12632   -5.36%
BenchmarkServerHandlerNoHeader        10911        10261   -5.96%

benchmark                        old allocs   new allocs    delta
BenchmarkServerHandlerTypeLen            20           19   -5.00%
BenchmarkServerHandlerNoLen              18           17   -5.56%
BenchmarkServerHandlerNoType             18           17   -5.56%
BenchmarkServerHandlerNoHeader           13           12   -7.69%

benchmark                         old bytes    new bytes    delta
BenchmarkServerHandlerTypeLen          1913         1878   -1.83%
BenchmarkServerHandlerNoLen            1878         1843   -1.86%
BenchmarkServerHandlerNoType           1878         1844   -1.81%
BenchmarkServerHandlerNoHeader         1085         1051   -3.13%
@bradfitz
Copy link
Contributor Author

bradfitz commented Apr 3, 2013

Comment 1:

CL at https://golang.org/cl/8297044 to be landed whenever the tree is willing.

@bradfitz
Copy link
Contributor Author

bradfitz commented Apr 3, 2013

Comment 2:

This issue was closed by revision 468851f.

Status changed to Fixed.

@bradfitz bradfitz self-assigned this Apr 3, 2013
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants