From 4f037da4620f417c842f53dbf579e2357c43bdd7 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Fri, 1 Sep 2017 12:09:29 +0200 Subject: [PATCH] Remove defer statement in hot path --- head.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/head.go b/head.go index d61d14b74..d49cea535 100644 --- a/head.go +++ b/head.go @@ -285,9 +285,9 @@ func (a *initAppender) Add(lset labels.Labels, t int64, v float64) (string, erro if a.app != nil { return a.app.Add(lset, t, v) } - if a.head.initTime(t) { - a.app = a.head.appender() - } + a.head.initTime(t) + a.app = a.head.appender() + return a.app.Add(lset, t, v) } @@ -1071,7 +1071,6 @@ func (s *memSeries) append(t int64, v float64) (success, chunkCreated bool) { const samplesPerChunk = 120 s.mtx.Lock() - defer s.mtx.Unlock() var c *memChunk @@ -1081,6 +1080,7 @@ func (s *memSeries) append(t int64, v float64) (success, chunkCreated bool) { } c = s.head() if c.maxTime >= t { + s.mtx.Unlock() return false, chunkCreated } if c.samples > samplesPerChunk/4 && t >= s.nextAt { @@ -1104,6 +1104,8 @@ func (s *memSeries) append(t int64, v float64) (success, chunkCreated bool) { s.sampleBuf[2] = s.sampleBuf[3] s.sampleBuf[3] = sample{t: t, v: v} + s.mtx.Unlock() + return true, chunkCreated }