Skip to content

Commit

Permalink
drpcmanager: reduce memory allocation in Reader (#40)
Browse files Browse the repository at this point in the history
Also, a `go fmt` while I'm here.
  • Loading branch information
ammario authored Sep 23, 2022
1 parent cd85be7 commit 858cfad
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions drpcwire/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ type Reader struct {

// A frame adds at most this many bytes of overhead to some data by prefixing
// the data with:
// 1: control byte
// 9: maximum varint stream id
// 9: maximum varint message id
// 9: maximum varint data length
//
// 1: control byte
// 9: maximum varint stream id
// 9: maximum varint message id
// 9: maximum varint data length
const maxFrameOverhead = 1 + 9 + 9 + 9

// NewReader constructs a Reader to read Packets from the io.Reader.
Expand All @@ -48,7 +49,9 @@ func NewReaderWithOptions(r io.Reader, opts ReaderOptions) *Reader {
return &Reader{
opts: opts,
r: r,
curr: make([]byte, 0, 64*1024),
// Err on the side of a smaller buffer since ReadPacket will lazily
// grow this buffer.
curr: make([]byte, 0, 4096),
id: ID{Stream: 1, Message: 1},
}
}
Expand Down

0 comments on commit 858cfad

Please sign in to comment.