mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
app/vmselect/netstorage: reduce the number of allocations for blockRefs objects in ProcessSearchQuery()
This should reduce pressure on Go GC at vmselect The change has been extracted from https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5527
This commit is contained in:
parent
508c608062
commit
678234e9f0
1 changed files with 12 additions and 3 deletions
|
@ -1180,10 +1180,14 @@ func ProcessSearchQuery(qt *querytracer.Tracer, sq *storage.SearchQuery, deadlin
|
|||
var buf []byte
|
||||
|
||||
// metricNamesBuf is used for holding all the loaded unique metric names.
|
||||
// It should reduce pressure on Go garbage collector by reducing
|
||||
// the number of memory allocations when constructing metricName string from byte slice.
|
||||
// It should reduce pressure on Go GC by reducing the number of string allocations
|
||||
// when constructing metricName string from byte slice.
|
||||
var metricNamesBuf []byte
|
||||
|
||||
// brssBuf is used for holding all the blockRefs objects across all the loaded time series.
|
||||
// It should reduce pressure on Go GC by reducing the number of blockRefs allocations.
|
||||
var brssBuf []blockRefs
|
||||
|
||||
for sr.NextMetricBlock() {
|
||||
blocksRead++
|
||||
if deadline.Exceeded() {
|
||||
|
@ -1208,7 +1212,12 @@ func ProcessSearchQuery(qt *querytracer.Tracer, sq *storage.SearchQuery, deadlin
|
|||
metricName := sr.MetricBlockRef.MetricName
|
||||
brs := m[string(metricName)]
|
||||
if brs == nil {
|
||||
brs = &blockRefs{}
|
||||
if cap(brssBuf) > len(brssBuf) {
|
||||
brssBuf = brssBuf[:len(brssBuf)+1]
|
||||
} else {
|
||||
brssBuf = append(brssBuf, blockRefs{})
|
||||
}
|
||||
brs = &brssBuf[len(brssBuf)-1]
|
||||
brs.brs = brs.brsPrealloc[:0]
|
||||
}
|
||||
brs.brs = append(brs.brs, blockRef{
|
||||
|
|
Loading…
Reference in a new issue