Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit b5de5f3

Browse files
committed
remove one pointer per cached metric
1 parent 5f49ca0 commit b5de5f3

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

mdata/cache/ccache.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (c *CCache) Add(metric, rawMetric string, prev uint32, itergen chunk.IterGe
132132
ccm, ok := c.metricCache[metric]
133133
if !ok {
134134
ccm = NewCCacheMetric()
135-
ccm.Init(rawMetric, prev, itergen)
135+
ccm.Init(uint8(len(metric)-len(rawMetric)), prev, itergen)
136136
c.metricCache[metric] = ccm
137137

138138
// if we do not have this raw key yet, create the entry with the association
@@ -187,9 +187,10 @@ func (c *CCache) evict(target *accnt.EvictTarget) {
187187
delete(c.metricCache, target.Metric)
188188

189189
// this key should alway be present, if not there there is a corruption of the state
190-
delete(c.metricRawKeys[ccm.RawMetric], target.Metric)
191-
if len(c.metricRawKeys[ccm.RawMetric]) == 0 {
192-
delete(c.metricRawKeys, ccm.RawMetric)
190+
rawMetric := target.Metric[:-ccm.SuffixLen]
191+
delete(c.metricRawKeys[rawMetric], target.Metric)
192+
if len(c.metricRawKeys[rawMetric]) == 0 {
193+
delete(c.metricRawKeys, rawMetric)
193194
}
194195
}
195196
}

mdata/cache/ccache_metric.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type CCacheMetric struct {
2020
// the list of chunk time stamps in ascending order
2121
keys []uint32
2222

23-
RawMetric string
23+
SuffixLen uint8
2424
}
2525

2626
func NewCCacheMetric() *CCacheMetric {
@@ -29,8 +29,8 @@ func NewCCacheMetric() *CCacheMetric {
2929
}
3030
}
3131

32-
func (mc *CCacheMetric) Init(rawMetric string, prev uint32, itergen chunk.IterGen) {
33-
mc.RawMetric = rawMetric
32+
func (mc *CCacheMetric) Init(suffixLen uint8, prev uint32, itergen chunk.IterGen) {
33+
mc.SuffixLen = suffixLen
3434
mc.Add(prev, itergen)
3535
}
3636

0 commit comments

Comments
 (0)