mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 15:16:42 +00:00
app/vmselect/promql: avoid memory allocations and copying from source timeseries to the returned result at timeseriesToResult()
This commit is contained in:
parent
dd92e2050f
commit
12e2bcdf81
3 changed files with 16 additions and 10 deletions
|
@ -130,9 +130,11 @@ func timeseriesToResult(tss []*timeseries, maySort bool) ([]netstorage.Result, e
|
|||
m[k] = struct{}{}
|
||||
|
||||
rs := &result[i]
|
||||
rs.MetricName.CopyFrom(&ts.MetricName)
|
||||
rs.Values = append(rs.Values[:0], ts.Values...)
|
||||
rs.Timestamps = append(rs.Timestamps[:0], ts.Timestamps...)
|
||||
rs.MetricName.MoveFrom(&ts.MetricName)
|
||||
rs.Values = ts.Values
|
||||
ts.Values = nil
|
||||
rs.Timestamps = ts.Timestamps
|
||||
ts.Timestamps = nil
|
||||
}
|
||||
bbPool.Put(bb)
|
||||
|
||||
|
|
|
@ -453,11 +453,9 @@ func mergeTimeseries(a, b []*timeseries, bStart int64, ec *EvalConfig) []*timese
|
|||
tmp.denyReuse = true
|
||||
tmp.Timestamps = sharedTimestamps
|
||||
tmp.Values = make([]float64, 0, len(tmp.Timestamps))
|
||||
// Do not use MetricName.CopyFrom for performance reasons.
|
||||
// It is safe to make shallow copy, since tsB must no longer used.
|
||||
tmp.MetricName = tsB.MetricName
|
||||
tmp.MetricName.MoveFrom(&tsB.MetricName)
|
||||
|
||||
bb.B = marshalMetricNameSorted(bb.B[:0], &tsB.MetricName)
|
||||
bb.B = marshalMetricNameSorted(bb.B[:0], &tmp.MetricName)
|
||||
tsA := m[string(bb.B)]
|
||||
if tsA == nil {
|
||||
tStart := ec.Start
|
||||
|
@ -481,9 +479,7 @@ func mergeTimeseries(a, b []*timeseries, bStart int64, ec *EvalConfig) []*timese
|
|||
var tmp timeseries
|
||||
tmp.denyReuse = true
|
||||
tmp.Timestamps = sharedTimestamps
|
||||
// Do not use MetricName.CopyFrom for performance reasons.
|
||||
// It is safe to make shallow copy, since tsA must no longer used.
|
||||
tmp.MetricName = tsA.MetricName
|
||||
tmp.MetricName.MoveFrom(&tsA.MetricName)
|
||||
tmp.Values = append(tmp.Values, tsA.Values...)
|
||||
|
||||
tStart := bStart
|
||||
|
|
|
@ -170,6 +170,14 @@ func (mn *MetricName) Reset() {
|
|||
mn.Tags = mn.Tags[:0]
|
||||
}
|
||||
|
||||
// MoveFrom moves src to mn.
|
||||
//
|
||||
// The src is reset after the call.
|
||||
func (mn *MetricName) MoveFrom(src *MetricName) {
|
||||
*mn = *src
|
||||
*src = MetricName{}
|
||||
}
|
||||
|
||||
// CopyFrom copies src to mn.
|
||||
func (mn *MetricName) CopyFrom(src *MetricName) {
|
||||
mn.AccountID = src.AccountID
|
||||
|
|
Loading…
Reference in a new issue