If we look at this code
|
func (c *LRUTxCache) Reset() { |
|
c.mtx.Lock() |
|
defer c.mtx.Unlock() |
|
|
|
c.cacheMap = make(map[types.TxKey]*list.Element, c.size) |
|
c.list.Init() |
|
} |
we can see that .Reset simply takes a lock then allocates a fresh map by discarding the previous one.
Suggestion
We can reduce on CPU & RAM pressure by using the map clearing idiom aka
func (c *LRUTxCache) Reset() {
c.mtx.Lock()
defer c.mtx.Unlock()
for key := range c.cacheMap {
delete(c.cacheMap, key)
}
c.list.Init()
}
which in performance wisdom is a known and accepted Go idiom for reducing CPU & RAM pressure by reusing the map.