From 6ad6f6a70e21dc45fc0c880b8732fb87c656c520 Mon Sep 17 00:00:00 2001 From: Roy Reznik Date: Fri, 20 Jun 2025 11:25:22 +0100 Subject: [PATCH] cmd/go: modload should use a read-write lock to improve concurrency --- src/cmd/go/internal/modload/init.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index 3cf447e648ce4e..1e80f6f2556a37 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -149,7 +149,7 @@ type MainModuleSet struct { // highest replaced version of each module path; empty string for wildcard-only replacements highestReplaced map[string]string - indexMu sync.Mutex + indexMu sync.RWMutex indices map[module.Version]*modFileIndex } @@ -228,8 +228,8 @@ func (mms *MainModuleSet) GetSingleIndexOrNil() *modFileIndex { } func (mms *MainModuleSet) Index(m module.Version) *modFileIndex { - mms.indexMu.Lock() - defer mms.indexMu.Unlock() + mms.indexMu.RLock() + defer mms.indexMu.RUnlock() return mms.indices[m] }