From 8bb6bc986d35758a84168d803e38e42dcfbf051e Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 11 Jun 2019 00:43:45 +0300 Subject: [PATCH] app/vmselect/promql: skip superflouos timestamps copying in `count_values` --- app/vmselect/promql/aggr.go | 2 +- app/vmselect/promql/timeseries.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/vmselect/promql/aggr.go b/app/vmselect/promql/aggr.go index 425f3f9987..8f6d5a7a7d 100644 --- a/app/vmselect/promql/aggr.go +++ b/app/vmselect/promql/aggr.go @@ -316,7 +316,7 @@ func aggrFuncCountValues(afa *aggrFuncArg) ([]*timeseries, error) { var rvs []*timeseries for _, v := range values { var dst timeseries - dst.CopyFrom(tss[0]) + dst.CopyFromShallowTimestamps(tss[0]) dst.MetricName.RemoveTag(dstLabel) dst.MetricName.AddTag(dstLabel, strconv.FormatFloat(v, 'g', -1, 64)) for i := range dst.Values { diff --git a/app/vmselect/promql/timeseries.go b/app/vmselect/promql/timeseries.go index 578e27ad6b..0b42403b96 100644 --- a/app/vmselect/promql/timeseries.go +++ b/app/vmselect/promql/timeseries.go @@ -38,11 +38,13 @@ func (ts *timeseries) String() string { return fmt.Sprintf("MetricName=%s, Values=%g, Timestamps=%d", &ts.MetricName, ts.Values, ts.Timestamps) } -func (ts *timeseries) CopyFrom(src *timeseries) { +func (ts *timeseries) CopyFromShallowTimestamps(src *timeseries) { ts.Reset() ts.MetricName.CopyFrom(&src.MetricName) ts.Values = append(ts.Values[:0], src.Values...) - ts.Timestamps = append(ts.Timestamps[:0], src.Timestamps...) + ts.Timestamps = src.Timestamps + + ts.denyReuse = true } func (ts *timeseries) CopyFromMetricNames(src *timeseries) {