http2: Add opt-in option to Framer to allow DataFrame struct reuse
The existing Framer in net/http2 allocates a new DataFrame struct
for each DataFrame read on calls to ReadFrame. The SetReuseFrame
option introduced here, if set on a Framer, allows the
Framer to reuse Frame objects and changes the ReadFrame API
so that returned Frame objects are only valid until the next call
to ReadFrame. This opt-in API now only implements reuse of DataFrames,
but it allows the Framer to reuse of any type of Frame.
The footprint caused by creation of new DataFrame structs per data
frame was noticed in micro benchmarks of "gRPC" server "streaming
throuhgput", which uses the Framer in this package. This benchmark
happened to use long lived http2 streams that do client-server "ping-pong"
requests with small data frames, and DataFrames were seen to be a
significant source of allocations.
Running local benchmarks with: (from x/net/http2 directory)
$ go test -run=^$ -bench=BenchmarkServerToClientStream
* expect an alloc reduction of at least 1 and a small memory reduction between
46216 ns/op 971 B/op 17 allocs/op
44952 ns/op 924 B/op 16 allocs/op
Run-TryBot: Brad Fitzpatrick <firstname.lastname@example.org>
TryBot-Result: Gobot Gobot <email@example.com>
Reviewed-by: Brad Fitzpatrick <firstname.lastname@example.org>
3 files changed