Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drpcmanager: reduce memory allocation in Reader #40

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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