Skip to content

Commit abb4a42

Browse files
committed
Reduce allocs but copy labels where needed.
1 parent dc2972f commit abb4a42

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

serialization/appender.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewAppender(ctx context.Context, ttl time.Duration, s types.Serializer, log
4343
// Append metric
4444
func (a *appender) Append(ref storage.SeriesRef, l labels.Labels, t int64, v float64) (storage.SeriesRef, error) {
4545
ts := types.GetMetricFromPool()
46-
ts.Labels = l
46+
ts.Labels = l.Copy()
4747
ts.TS = t
4848
ts.Value = v
4949
ts.Hash = l.Hash()
@@ -70,7 +70,7 @@ func (a *appender) AppendExemplar(ref storage.SeriesRef, _ labels.Labels, e exem
7070
ts := types.GetMetricFromPool()
7171
ts.Hash = e.Labels.Hash()
7272
ts.TS = e.Ts
73-
ts.Labels = e.Labels
73+
ts.Labels = e.Labels.Copy()
7474
ts.Hash = e.Labels.Hash()
7575
err := a.s.SendSeries(a.ctx, ts)
7676
return ref, err
@@ -83,7 +83,7 @@ func (a *appender) AppendHistogram(ref storage.SeriesRef, l labels.Labels, t int
8383
return ref, nil
8484
}
8585
ts := types.GetMetricFromPool()
86-
ts.Labels = l
86+
ts.Labels = l.Copy()
8787
ts.TS = t
8888
if h != nil {
8989
ts.Histogram = h

types/metric.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ func PutMetricIntoPool(m *Metric) {
6666
m.Hash = 0
6767
m.TS = 0
6868
m.Value = 0
69-
// We explicitly need this to be nil since labels are not safe to reuse.
70-
m.Labels = nil
69+
m.Labels = m.Labels[:0]
7170
m.Histogram = nil
7271
m.FloatHistogram = nil
7372

0 commit comments

Comments
 (0)