MCPcopy Create free account
hub / github.com/cortexproject/cortex / ReuseTimeseries

Function ReuseTimeseries

pkg/cortexpb/timeseries.go:332–355  ·  view source on GitHub ↗

ReuseTimeseries puts the timeseries back into a sync.Pool for reuse.

(ts *TimeSeries)

Source from the content-addressed store, hash-verified

330
331// ReuseTimeseries puts the timeseries back into a sync.Pool for reuse.
332func ReuseTimeseries(ts *TimeSeries) {
333 // Name and Value may point into a large gRPC buffer, so clear the reference to allow GC
334 for i := 0; i < len(ts.Labels); i++ {
335 ts.Labels[i].Name = ""
336 ts.Labels[i].Value = ""
337 }
338 ts.Labels = ts.Labels[:0]
339 ts.Samples = ts.Samples[:0]
340 // Name and Value may point into a large gRPC buffer, so clear the reference in each exemplar to allow GC
341 for i := range ts.Exemplars {
342 for j := range ts.Exemplars[i].Labels {
343 ts.Exemplars[i].Labels[j].Name = ""
344 ts.Exemplars[i].Labels[j].Value = ""
345 }
346 }
347
348 for i := range ts.Histograms {
349 ts.Histograms[i].Reset()
350 }
351
352 ts.Exemplars = ts.Exemplars[:0]
353 ts.Histograms = ts.Histograms[:0]
354 timeSeriesPool.Put(ts)
355}

Callers 2

TestTimeseriesFromPoolFunction · 0.85
ReuseSliceFunction · 0.85

Calls 2

PutMethod · 0.65
ResetMethod · 0.45

Tested by 1

TestTimeseriesFromPoolFunction · 0.68