app/vmselect/netstorage: cache canonical MetricName for time series returned from the storage

This reduces memory allocations for repeated queries, which return (almost) the same set of time series.
This commit is contained in:
Aliaksandr Valialkin 2023-01-09 21:53:07 -08:00
parent b7a4650ab0
commit 2483c67579
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -1261,9 +1261,9 @@ func (tbfw *tmpBlocksFileWrapper) RegisterAndWriteBlock(mb *storage.MetricBlock,
if err != nil {
return err
}
metricName := mb.MetricName
metricName := bytesutil.InternBytes(mb.MetricName)
m := tbfw.ms[workerID]
addrs := m[string(metricName)]
addrs := m[metricName]
if addrs == nil {
addrs = &blockAddrs{}
}
@ -1272,9 +1272,8 @@ func (tbfw *tmpBlocksFileWrapper) RegisterAndWriteBlock(mb *storage.MetricBlock,
// An optimization for big number of time series with long names: store only a single copy of metricNameStr
// in both tbfw.orderedMetricNamess and tbfw.ms.
orderedMetricNames := tbfw.orderedMetricNamess[workerID]
orderedMetricNames = append(orderedMetricNames, string(metricName))
metricNameStr := orderedMetricNames[len(orderedMetricNames)-1]
m[metricNameStr] = addrs
orderedMetricNames = append(orderedMetricNames, metricName)
m[metricName] = addrs
tbfw.orderedMetricNamess[workerID] = orderedMetricNames
}
return nil