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

Commit

Permalink
remove one pointer per cached metric
Browse files Browse the repository at this point in the history
  • Loading branch information
replay committed Jan 4, 2018
1 parent 5f49ca0 commit b5de5f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions mdata/cache/ccache.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *CCache) Add(metric, rawMetric string, prev uint32, itergen chunk.IterGe
ccm, ok := c.metricCache[metric]
if !ok {
ccm = NewCCacheMetric()
ccm.Init(rawMetric, prev, itergen)
ccm.Init(uint8(len(metric)-len(rawMetric)), prev, itergen)
c.metricCache[metric] = ccm

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

// this key should alway be present, if not there there is a corruption of the state
delete(c.metricRawKeys[ccm.RawMetric], target.Metric)
if len(c.metricRawKeys[ccm.RawMetric]) == 0 {
delete(c.metricRawKeys, ccm.RawMetric)
rawMetric := target.Metric[:-ccm.SuffixLen]
delete(c.metricRawKeys[rawMetric], target.Metric)
if len(c.metricRawKeys[rawMetric]) == 0 {
delete(c.metricRawKeys, rawMetric)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions mdata/cache/ccache_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type CCacheMetric struct {
// the list of chunk time stamps in ascending order
keys []uint32

RawMetric string
SuffixLen uint8
}

func NewCCacheMetric() *CCacheMetric {
Expand All @@ -29,8 +29,8 @@ func NewCCacheMetric() *CCacheMetric {
}
}

func (mc *CCacheMetric) Init(rawMetric string, prev uint32, itergen chunk.IterGen) {
mc.RawMetric = rawMetric
func (mc *CCacheMetric) Init(suffixLen uint8, prev uint32, itergen chunk.IterGen) {
mc.SuffixLen = suffixLen
mc.Add(prev, itergen)
}

Expand Down

0 comments on commit b5de5f3

Please sign in to comment.