mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
app/vmselect/promql: avoid memory allocations and copying from source timeseries to the returned result at timeseriesToResult()
This commit is contained in:
parent
26cf680468
commit
2f3ddd4884
@ -129,9 +129,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)
|
||||
|
||||
|
@ -497,11 +497,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
|
||||
@ -525,9 +523,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
|
||||
|
@ -165,6 +165,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) {
|
||||
if cap(mn.MetricGroup) > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user