Skip to content

Commit

Permalink
Reduce allocs but copy labels where needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdurham committed Dec 27, 2024
1 parent dc2972f commit abb4a42
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions serialization/appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewAppender(ctx context.Context, ttl time.Duration, s types.Serializer, log
// Append metric
func (a *appender) Append(ref storage.SeriesRef, l labels.Labels, t int64, v float64) (storage.SeriesRef, error) {
ts := types.GetMetricFromPool()
ts.Labels = l
ts.Labels = l.Copy()
ts.TS = t
ts.Value = v
ts.Hash = l.Hash()
Expand All @@ -70,7 +70,7 @@ func (a *appender) AppendExemplar(ref storage.SeriesRef, _ labels.Labels, e exem
ts := types.GetMetricFromPool()
ts.Hash = e.Labels.Hash()
ts.TS = e.Ts
ts.Labels = e.Labels
ts.Labels = e.Labels.Copy()
ts.Hash = e.Labels.Hash()
err := a.s.SendSeries(a.ctx, ts)
return ref, err
Expand All @@ -83,7 +83,7 @@ func (a *appender) AppendHistogram(ref storage.SeriesRef, l labels.Labels, t int
return ref, nil
}
ts := types.GetMetricFromPool()
ts.Labels = l
ts.Labels = l.Copy()
ts.TS = t
if h != nil {
ts.Histogram = h
Expand Down
3 changes: 1 addition & 2 deletions types/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func PutMetricIntoPool(m *Metric) {
m.Hash = 0
m.TS = 0
m.Value = 0
// We explicitly need this to be nil since labels are not safe to reuse.
m.Labels = nil
m.Labels = m.Labels[:0]
m.Histogram = nil
m.FloatHistogram = nil

Expand Down

0 comments on commit abb4a42

Please sign in to comment.