mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
app/vmselect/promql: reduce the number of memory allocations inside copyTimeseriesShallow()
Previously the number of memory allocations inside copyTimeseriesShallow() was equal to 1+len(tss) Reduce this number to 2 by pre-allocating a slice of timeseries structs with len(tss) length.
This commit is contained in:
parent
c8e6e47e2a
commit
faee0e43d1
1 changed files with 9 additions and 8 deletions
|
@ -2743,14 +2743,15 @@ func copyTimeseriesMetricNames(tss []*timeseries, makeCopy bool) []*timeseries {
|
||||||
return rvs
|
return rvs
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyTimeseriesShallow returns a copy of arg with shallow copies of MetricNames,
|
// copyTimeseriesShallow returns a copy of src with shallow copies of MetricNames, Timestamps and Values.
|
||||||
// Timestamps and Values.
|
func copyTimeseriesShallow(src []*timeseries) []*timeseries {
|
||||||
func copyTimeseriesShallow(arg []*timeseries) []*timeseries {
|
tss := make([]timeseries, len(src))
|
||||||
rvs := make([]*timeseries, len(arg))
|
for i, src := range src {
|
||||||
for i, src := range arg {
|
tss[i].CopyShallow(src)
|
||||||
var dst timeseries
|
}
|
||||||
dst.CopyShallow(src)
|
rvs := make([]*timeseries, len(tss))
|
||||||
rvs[i] = &dst
|
for i := range tss {
|
||||||
|
rvs[i] = &tss[i]
|
||||||
}
|
}
|
||||||
return rvs
|
return rvs
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue