diff options
author | Bryan C. Mills <bcmills@google.com> | 2022-01-26 12:45:12 -0500 |
---|---|---|
committer | Bryan Mills <bcmills@google.com> | 2022-01-26 19:17:30 +0000 |
commit | 946a8669d92f18a0029abaed9cea36194562a957 (patch) | |
tree | 586a8403f5108127fffd485b2224e88cf44eb4e4 | |
parent | 719e9894f9a471cd74b8469d9231cd2798b33999 (diff) | |
download | go-946a8669d92f18a0029abaed9cea36194562a957.tar.gz go-946a8669d92f18a0029abaed9cea36194562a957.zip |
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 <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
-rw-r--r-- | src/cmd/api/goapi.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index 036aefe4d8..5ae059e4ce 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -459,8 +459,11 @@ type listImports struct { var listCache sync.Map // map[string]listImports, keyed by contextName -// listSem is a semaphore restricting concurrent invocations of 'go list'. -var listSem = make(chan semToken, ((runtime.GOMAXPROCS(0)-1)/2)+1) +// listSem is a semaphore restricting concurrent invocations of 'go list'. 'go +// list' has its own internal concurrency, so we use a hard-coded constant (to +// allow the I/O-intensive phases of 'go list' to overlap) instead of scaling +// all the way up to GOMAXPROCS. +var listSem = make(chan semToken, 2) type semToken struct{} |