Skip to content

Commit 946a866

Browse files
author
Bryan C. Mills
committed
cmd/api: reduce parallel 'go list' invocations to a constant
'go list' has its own internal parallelism, so invoking in in parallel can produce up to quadratic peak memory usage. Running 'go list' is also very I/O-intensive, so the higher parallelism does substantially improve latency; unfortunately, we lack a good way to balance latency against memory footprint, so we need to sacrifice some latency for reliability. Fixes #49957. Change-Id: Ib53990b46acf4cc67a9141644d97282964d6442d Reviewed-on: https://go-review.googlesource.com/c/go/+/380994 Trust: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 719e989 commit 946a866

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/cmd/api/goapi.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,11 @@ type listImports struct {
459459

460460
var listCache sync.Map // map[string]listImports, keyed by contextName
461461

462-
// listSem is a semaphore restricting concurrent invocations of 'go list'.
463-
var listSem = make(chan semToken, ((runtime.GOMAXPROCS(0)-1)/2)+1)
462+
// listSem is a semaphore restricting concurrent invocations of 'go list'. 'go
463+
// list' has its own internal concurrency, so we use a hard-coded constant (to
464+
// allow the I/O-intensive phases of 'go list' to overlap) instead of scaling
465+
// all the way up to GOMAXPROCS.
466+
var listSem = make(chan semToken, 2)
464467

465468
type semToken struct{}
466469

0 commit comments

Comments
 (0)