diff --git a/http2/frame_test.go b/http2/frame_test.go index 86e5d4f80..cd5842ba4 100644 --- a/http2/frame_test.go +++ b/http2/frame_test.go @@ -1258,3 +1258,20 @@ func TestSettingsDuplicates(t *testing.T) { } } + +func BenchmarkParseDataFrames(b *testing.B) { + fr, _ := testFramer() + fr.SetReuseFrames() + payload := []byte("foo") + for i := 0; i < b.N; i++ { + parseDataFrame(fr.frameCache, FrameHeader{StreamID: 3}, func(s string) {}, payload) + } +} + +func BenchmarkParseDataFramesWithoutReuse(b *testing.B) { + fr, _ := testFramer() + payload := []byte("foo") + for i := 0; i < b.N; i++ { + parseDataFrame(fr.frameCache, FrameHeader{StreamID: 3}, func(s string) {}, payload) + } +} diff --git a/http2/server.go b/http2/server.go index 6c349f3ec..86b78c7ec 100644 --- a/http2/server.go +++ b/http2/server.go @@ -494,6 +494,7 @@ func (s *Server) serveConn(c net.Conn, opts *ServeConnOpts, newf func(*serverCon sc.hpackEncoder.SetMaxDynamicTableSizeLimit(s.maxEncoderHeaderTableSize()) fr := NewFramer(sc.bw, c) + fr.SetReuseFrames() if s.CountError != nil { fr.countError = s.CountError } diff --git a/http2/transport.go b/http2/transport.go index 61f511f97..64c38c5f3 100644 --- a/http2/transport.go +++ b/http2/transport.go @@ -813,6 +813,7 @@ func (t *Transport) newClientConn(c net.Conn, singleUse bool) (*ClientConn, erro }) cc.br = bufio.NewReader(c) cc.fr = NewFramer(cc.bw, cc.br) + cc.fr.SetReuseFrames() if t.maxFrameReadSize() != 0 { cc.fr.SetMaxReadFrameSize(t.maxFrameReadSize()) }