Skip to content

Commit

Permalink
removing the unnecessary mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
Thejas-bhat committed Apr 10, 2024
1 parent f559330 commit 97f15cb
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions faiss_vector_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ type ewma struct {
type cacheEntry struct {
tracker *ewma
refs int64

m sync.RWMutex
index *faiss.IndexImpl
index *faiss.IndexImpl
}

func newVectorIndexCache() *vecIndexCache {
Expand Down Expand Up @@ -82,10 +80,8 @@ func (vc *vecIndexCache) createAndCacheVectorIndex(fieldID uint16,
// cached.
entry, present := vc.cache[fieldID]
if present {
entry.m.RLock()
rv := entry.index
entry.incHit()
entry.m.RUnlock()
return rv, nil
}

Expand Down Expand Up @@ -121,10 +117,7 @@ func (vc *vecIndexCache) isIndexCached(fieldID uint16) (*faiss.IndexImpl, bool)
return nil, false
}

entry.m.RLock()
rv := entry.index
entry.m.RUnlock()

return rv, present && (rv != nil)
}

Expand Down Expand Up @@ -230,8 +223,6 @@ func (vc *cacheEntry) decRef() {
}

func (vc *cacheEntry) closeIndex() {
vc.m.Lock()
vc.index.Close()
vc.index = nil
vc.m.Unlock()
}

0 comments on commit 97f15cb

Please sign in to comment.