Skip to content

Commit

Permalink
Decode reports from a byte buffer
Browse files Browse the repository at this point in the history
Reading and uncompressing the entire message into memory first allows
the decoder to avoid memory allocations in field names, etc.
  • Loading branch information
bboreham authored and rade committed Nov 29, 2017
1 parent cdbc01e commit 05d5d33
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions report/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ func (rep *Report) ReadBinary(r io.Reader, gzipped bool, codecHandle codec.Handl
return err
}
}
if log.GetLevel() == log.DebugLevel {
r = byteCounter{next: r, count: &uncompressedSize}
// Read everything into memory before decoding: it's faster
buf, err := ioutil.ReadAll(r)
if err != nil {
return err
}
if err := codec.NewDecoder(r, codecHandle).Decode(&rep); err != nil {
uncompressedSize = uint64(len(buf))
if err := rep.ReadBytes(buf, codecHandle); err != nil {
return err
}
log.Debugf(
Expand Down

0 comments on commit 05d5d33

Please sign in to comment.