app/vmselect/promql: intern output series names during incremental aggregation

This should reduce the number of memory allocations for repeated queries
This commit is contained in:
Aliaksandr Valialkin 2023-01-09 22:11:33 -08:00
parent df2a494a7c
commit 21ee9a1fab
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -5,6 +5,7 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"github.com/VictoriaMetrics/metricsql" "github.com/VictoriaMetrics/metricsql"
) )
@ -98,7 +99,8 @@ func (iafc *incrementalAggrFuncContext) updateTimeseries(tsOrig *timeseries, wor
removeGroupTags(&ts.MetricName, &iafc.ae.Modifier) removeGroupTags(&ts.MetricName, &iafc.ae.Modifier)
bb := bbPool.Get() bb := bbPool.Get()
bb.B = marshalMetricNameSorted(bb.B[:0], &ts.MetricName) bb.B = marshalMetricNameSorted(bb.B[:0], &ts.MetricName)
iac := m[string(bb.B)] k := bytesutil.InternBytes(bb.B)
iac := m[k]
if iac == nil { if iac == nil {
if iafc.ae.Limit > 0 && len(m) >= iafc.ae.Limit { if iafc.ae.Limit > 0 && len(m) >= iafc.ae.Limit {
// Skip this time series, since the limit on the number of output time series has been already reached. // Skip this time series, since the limit on the number of output time series has been already reached.
@ -117,7 +119,7 @@ func (iafc *incrementalAggrFuncContext) updateTimeseries(tsOrig *timeseries, wor
ts: tsAggr, ts: tsAggr,
values: make([]float64, len(ts.Values)), values: make([]float64, len(ts.Values)),
} }
m[string(bb.B)] = iac m[k] = iac
} }
bbPool.Put(bb) bbPool.Put(bb)
iafc.callbacks.updateAggrFunc(iac, ts.Values) iafc.callbacks.updateAggrFunc(iac, ts.Values)