Don't clone the metric if there's no remote writes.

The metric clone can't be further optimised, and is a
non-trivial memory allocation cost so fast path it
if there's no remote writes configured.
This commit is contained in:
Brian Brazil 2016-12-21 11:33:28 +00:00
parent 6c07453ec1
commit 1b8a474612
1 changed files with 5 additions and 3 deletions

View File

@ -77,6 +77,10 @@ func (s *ReloadableStorage) Append(smpl *model.Sample) error {
s.mtx.RLock()
defer s.mtx.RUnlock()
if s.queue == nil {
return nil
}
var snew model.Sample
snew = *smpl
snew.Metric = smpl.Metric.Clone()
@ -92,9 +96,7 @@ func (s *ReloadableStorage) Append(smpl *model.Sample) error {
if snew.Metric == nil {
return nil
}
if s.queue != nil {
s.queue.Append(&snew)
}
s.queue.Append(&snew)
return nil
}