mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-29 02:01:43 +00:00
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:
committed by
Matthias Radestock
parent
cdbc01ecf9
commit
05d5d339c4
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user