Skip to content

Commit 9648801

Browse files
committed
perf: calculate xxhash of metric name only once in Add()
Store hash result in variable to avoid computing xxhash.Sum64 twice when checking and adding to bloom filter.
1 parent 6d7e866 commit 9648801

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cache/cache.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ func (c *Cache) Add(p *points.Points) {
334334
if c.newMetricsChan != nil && c.newMetricCf != nil {
335335
// add metric to new metric channel if missed in bloom
336336
// despite what we have it in cache (new behaviour)
337-
if !c.newMetricCf.Has(xxhash.Sum64([]byte(p.Metric))) {
337+
hash := xxhash.Sum64([]byte(p.Metric))
338+
if !c.newMetricCf.Has(hash) {
338339
sendMetricToNewMetricChan(c, p.Metric)
339-
c.newMetricCf.Add(xxhash.Sum64([]byte(p.Metric)))
340+
c.newMetricCf.Add(hash)
340341
}
341342

342343
}

0 commit comments

Comments
 (0)