From 030ce454f330871a6be729d7ca8c6ac33e1bbbb5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 16 Mar 2026 04:03:41 +0200 Subject: Use read lock for cache misses in completionState.cacheGet Co-Authored-By: Claude Opus 4.6 --- internal/lsp/completion_state.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'internal/lsp') diff --git a/internal/lsp/completion_state.go b/internal/lsp/completion_state.go index 9799561..9f034ab 100644 --- a/internal/lsp/completion_state.go +++ b/internal/lsp/completion_state.go @@ -66,13 +66,18 @@ func (s *completionState) takePendingCompletion(key string) []CompletionItem { return cpy } +// cacheGet returns the cached value for key. A read lock is sufficient for +// cache misses. On a hit we must promote to a write lock so touchLocked can +// update the LRU order. func (s *completionState) cacheGet(key string) (string, bool) { - s.stateMu.Lock() - defer s.stateMu.Unlock() + s.stateMu.RLock() v, ok := s.compCache[key] + s.stateMu.RUnlock() if !ok { return "", false } + s.stateMu.Lock() + defer s.stateMu.Unlock() s.touchLocked(key) return v, true } -- cgit v1.2.3