mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01: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
@ -2743,14 +2743,15 @@ func copyTimeseriesMetricNames(tss []*timeseries, makeCopy bool) []*timeseries {
|
||||
return rvs
|
||||
}
|
||||
|
||||
// copyTimeseriesShallow returns a copy of arg with shallow copies of MetricNames,
|
||||
// Timestamps and Values.
|
||||
func copyTimeseriesShallow(arg []*timeseries) []*timeseries {
|
||||
rvs := make([]*timeseries, len(arg))
|
||||
for i, src := range arg {
|
||||
var dst timeseries
|
||||
dst.CopyShallow(src)
|
||||
rvs[i] = &dst
|
||||
// copyTimeseriesShallow returns a copy of src with shallow copies of MetricNames, Timestamps and Values.
|
||||
func copyTimeseriesShallow(src []*timeseries) []*timeseries {
|
||||
tss := make([]timeseries, len(src))
|
||||
for i, src := range src {
|
||||
tss[i].CopyShallow(src)
|
||||
}
|
||||
rvs := make([]*timeseries, len(tss))
|
||||
for i := range tss {
|
||||
rvs[i] = &tss[i]
|
||||
}
|
||||
return rvs
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user