Decode reports from a byte buffer

Reading and uncompressing the entire message into memory first allows
the decoder to avoid memory allocations in field names, etc.
This commit is contained in:
Bryan Boreham
2017-03-24 09:49:30 +00:00
committed by Matthias Radestock
parent cdbc01ecf9
commit 05d5d339c4

View File

@@ -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(