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. bpf/
  2. context/
  3. dict/
  4. dns/
  5. html/
  6. http/
  7. http2/
  8. icmp/
  9. idna/
  10. internal/
  11. ipv4/
  12. ipv6/
  13. lif/
  14. nettest/
  15. netutil/
  16. proxy/
  17. publicsuffix/
  18. route/
  19. trace/
  20. webdav/
  21. websocket/
  22. xsrftoken/
  23. .gitattributes
  24. .gitignore
  25. AUTHORS
  26. codereview.cfg
  27. CONTRIBUTING.md
  28. CONTRIBUTORS
  29. go.mod
  30. go.sum
  31. LICENSE
  32. PATENTS
  33. README.md
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.