http2: reduce allocations of (*clientConnReadLoop).handleReponse

Reduce allocation by using 1 capacity slices out of a single
pre-allocated slice for header values, similarly to how it is done
in textproto.(*Reader).ReadMIMEHeader.

  name                                   old time/op    new time/op    delta
  ClientResponseHeaders/___0_Headers-16    82.3µs ± 7%    76.4µs ± 4%   -7.18%  (p=0.000 n=10+10)
  ClientResponseHeaders/__10_Headers-16     101µs ± 2%      99µs ± 3%   -2.00%  (p=0.016 n=8+10)
  ClientResponseHeaders/_100_Headers-16     213µs ± 2%     202µs ± 4%   -4.96%  (p=0.000 n=9+9)
  ClientResponseHeaders/1000_Headers-16    2.28ms ± 1%    2.15ms ± 2%   -5.58%  (p=0.000 n=8+10)

  name                                   old alloc/op   new alloc/op   delta
  ClientResponseHeaders/___0_Headers-16    4.60kB ± 0%    4.60kB ± 0%     ~     (p=0.201 n=10+10)
  ClientResponseHeaders/__10_Headers-16    9.01kB ± 0%    8.66kB ± 0%   -3.96%  (p=0.000 n=10+10)
  ClientResponseHeaders/_100_Headers-16    54.4kB ± 0%    48.4kB ± 0%  -11.01%  (p=0.000 n=10+10)
  ClientResponseHeaders/1000_Headers-16     702kB ± 0%     595kB ± 0%  -15.28%  (p=0.000 n=10+9)

  name                                   old allocs/op  new allocs/op  delta
  ClientResponseHeaders/___0_Headers-16      57.0 ± 0%      56.0 ± 0%   -1.75%  (p=0.000 n=10+10)
  ClientResponseHeaders/__10_Headers-16       135 ± 0%       123 ± 0%   -8.89%  (p=0.000 n=10+10)
  ClientResponseHeaders/_100_Headers-16       786 ± 0%       679 ± 0%  -13.61%  (p=0.000 n=10+10)
  ClientResponseHeaders/1000_Headers-16     8.14k ± 0%     7.11k ± 0%  -12.65%  (p=0.000 n=10+10)

Fixes golang/go#37853

Change-Id: I0bc6d879293a202a2742a06aca0b6dacfae7fc5f
Reviewed-on: https://go-review.googlesource.com/c/net/+/223783
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2 files changed
tree: 0d3c292e82071be7f74b79f83bbaa3f1dcb0298a
  1. .gitattributes
  2. .gitignore
  3. AUTHORS
  4. CONTRIBUTING.md
  5. CONTRIBUTORS
  6. LICENSE
  7. PATENTS
  8. README.md
  9. bpf/
  10. codereview.cfg
  11. context/
  12. dict/
  13. dns/
  14. go.mod
  15. go.sum
  16. html/
  17. http/
  18. http2/
  19. icmp/
  20. idna/
  21. internal/
  22. ipv4/
  23. ipv6/
  24. lif/
  25. nettest/
  26. netutil/
  27. proxy/
  28. publicsuffix/
  29. route/
  30. trace/
  31. webdav/
  32. websocket/
  33. xsrftoken/
README.md

Go Networking

This repository holds supplementary Go networking libraries.

Download/Install

The easiest way to install is to run go get -u golang.org/x/net. You can also manually git clone the repository to $GOPATH/src/golang.org/x/net.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html. The main issue tracker for the net repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/net:” in the subject line, so it is easy to find.