Commit Graph

3 Commits

Author SHA1 Message Date
Felix Lange
9afc6816d2
common/lru: add generic LRU implementation (#26162)
It seems there is no fully typed library implementation of an LRU cache.
So I wrote one. Method names are the same as github.com/hashicorp/golang-lru,
and the new type can be used as a drop-in replacement.

Two reasons to do this:

- It's much easier to understand what a cache is for when the types are right there.
- Performance: the new implementation is slightly faster and performs zero memory
   allocations in Add when the cache is at capacity. Overall, memory usage of the cache
   is much reduced because keys are values are no longer wrapped in interface.
2022-11-14 15:41:56 +01:00
Martin Holst Swende
8334b5f51a
common/lru: fix race in lru (#26164)
This fixes a problem in the SizeConstrainedLRU. The SCLRU uses an underlying simple lru which is not thread safe.
During the Get operation, the recentness of the accessed item is updated, so it is not a pure read-operation. Therefore, the mutex we need is a full mutex, not RLock.

This PR changes the mutex to be a regular Mutex, instead of RWMutex, so a reviewer can at a glance see that all affected locations are fixed.
2022-11-11 19:48:36 +01:00
Martin Holst Swende
5fded04037
core/state: replace fastcache code cache with gc-friendly structure (#26092)
This PR replaces fastcache with a pretty simple LRU which does not require explicit closing.
2022-11-09 08:06:02 +01:00