From a3a09a3c6e41e009f7d94acfcdc019a60ba1df9d Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 16 Feb 2021 15:43:07 +0200 Subject: [PATCH] app/vmselect/netstorage: use unsafe string as a key for a map when the map already contains the given key This should prevent from a memory allocation and a string copy. --- app/vmselect/netstorage/netstorage.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/vmselect/netstorage/netstorage.go b/app/vmselect/netstorage/netstorage.go index 9d715fee1e..de67195d23 100644 --- a/app/vmselect/netstorage/netstorage.go +++ b/app/vmselect/netstorage/netstorage.go @@ -1085,11 +1085,12 @@ func (tbfw *tmpBlocksFileWrapper) RegisterAndWriteBlock(mb *storage.MetricBlock) tmpBufPool.Put(bb) if err == nil { metricName := mb.MetricName - addrs := tbfw.m[string(metricName)] + metricNameStrUnsafe := bytesutil.ToUnsafeString(metricName) + addrs := tbfw.m[metricNameStrUnsafe] addrs = append(addrs, addr) if len(addrs) > 1 { // An optimization: avoid memory allocation and copy for already existing metricName key in tbfw.m. - tbfw.m[string(metricName)] = addrs + tbfw.m[metricNameStrUnsafe] = addrs } else { // An optimization for big number of time series with long names: store only a single copy of metricNameStr // in both tbfw.orderedMetricNames and tbfw.m.