From df2a494a7ce8041bc8be1e45cd52c3a518c3e522 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 9 Jan 2023 22:03:21 -0800 Subject: [PATCH] app/vmselect/netstorage: pre-allocate 4 block references per each time series during querying Usually the number of blocks returned per each time series during queries is around 4. So it is a good idea to pre-allocate 4 block references per time series in order to reduce the number of memory allocations. --- app/vmselect/netstorage/netstorage.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/vmselect/netstorage/netstorage.go b/app/vmselect/netstorage/netstorage.go index 408766e90..d599e1a62 100644 --- a/app/vmselect/netstorage/netstorage.go +++ b/app/vmselect/netstorage/netstorage.go @@ -1061,7 +1061,8 @@ func ProcessSearchQuery(qt *querytracer.Tracer, sq *storage.SearchQuery, deadlin maxSeriesCount := sr.Init(qt, vmstorage.Storage, tfss, tr, sq.MaxMetrics, deadline.Deadline()) indexSearchDuration.UpdateDuration(startTime) type blockRefs struct { - brs []blockRef + brsPrealloc [4]blockRef + brs []blockRef } m := make(map[string]*blockRefs, maxSeriesCount) orderedMetricNames := make([]string, 0, maxSeriesCount) @@ -1094,6 +1095,7 @@ func ProcessSearchQuery(qt *querytracer.Tracer, sq *storage.SearchQuery, deadlin brs := m[metricName] if brs == nil { brs = &blockRefs{} + brs.brs = brs.brsPrealloc[:0] } brs.brs = append(brs.brs, blockRef{ partRef: br.PartRef(),