mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
da05c10544
commit
a3a09a3c6e
1 changed files with 3 additions and 2 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue