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.
This commit is contained in:
Aliaksandr Valialkin 2021-02-16 15:43:07 +02:00
parent da05c10544
commit a3a09a3c6e

View file

@ -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.