switch to standard lock to help cache perf (#730)

This commit is contained in:
hexoscott 2022-11-08 16:20:47 +00:00 committed by GitHub
parent 19804fd971
commit 875b19b2b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -358,8 +358,10 @@ func (c *Coherent) View(ctx context.Context, tx kv.Tx) (CacheView, error) {
} }
func (c *Coherent) getFromCache(k []byte, id uint64, code bool) (*Element, *CoherentRoot, error) { func (c *Coherent) getFromCache(k []byte, id uint64, code bool) (*Element, *CoherentRoot, error) {
c.lock.RLock() // using the full lock here rather than RLock as RLock causes a lot of calls to runtime.usleep degrading
defer c.lock.RUnlock() // performance under load
c.lock.Lock()
defer c.lock.Unlock()
r, ok := c.roots[id] r, ok := c.roots[id]
if !ok { if !ok {
return nil, r, fmt.Errorf("too old ViewID: %d, latestStateVersionID=%d", id, c.latestStateVersionID) return nil, r, fmt.Errorf("too old ViewID: %d, latestStateVersionID=%d", id, c.latestStateVersionID)