Skip to content

Commit d362be0

Browse files
committed
gopls/internal/lsp/filecache: reduce GC frequency
This is a mitigation for observed high idle CPU usage. Also, eliminate the obsolete special case for builders, now that each CI run gets a fresh GOPLSCACHE. Updates golang/go#61049 Change-Id: I8689ab9ebf4d9ef75d9e1a0f4bc7bc9d109bef71 Reviewed-on: https://go-review.googlesource.com/c/tools/+/506815 TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Alan Donovan <[email protected]>
1 parent 969078b commit d362be0

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

gopls/internal/lsp/filecache/filecache.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,16 @@ func hashExecutable() (hash [32]byte, err error) {
385385
// process, possibly running a different version of gopls, possibly
386386
// running concurrently.
387387
func gc(goplsDir string) {
388-
const period = 1 * time.Minute // period between collections
388+
// period between collections
389+
//
390+
// This was increased from 1 minute as an immediate measure to
391+
// reduce the CPU cost of gopls when idle, which was around
392+
// 15% of a core (#61049). A better solution might be to avoid
393+
// walking the entire tree every period. e.g. walk only the
394+
// subtree corresponding to this gopls executable every period,
395+
// and the subtrees for other gopls instances every hour.
396+
const period = 5 * time.Minute
397+
389398
// Sleep statDelay*batchSize between stats to smooth out I/O.
390399
//
391400
// The constants below were chosen using the following heuristics:
@@ -396,17 +405,7 @@ func gc(goplsDir string) {
396405
// sleeping after every stat (due to OS optimizations).
397406
const statDelay = 100 * time.Microsecond // average delay between stats, to smooth out I/O
398407
const batchSize = 1000 // # of stats to process before sleeping
399-
maxAge := 5 * 24 * time.Hour // max time since last access before file is deleted
400-
401-
// This environment variable is set when running under a Go test builder.
402-
// We use it to trigger much more aggressive cache eviction to prevent
403-
// filling of the tmp volume by short-lived test processes.
404-
// A single run of the gopls tests takes on the order of a minute
405-
// and produces <50MB of cache data, so these are still generous.
406-
if os.Getenv("GO_BUILDER_NAME") != "" {
407-
maxAge = 1 * time.Hour
408-
SetBudget(250 * 1e6) // 250MB
409-
}
408+
const maxAge = 5 * 24 * time.Hour // max time since last access before file is deleted
410409

411410
// The macOS filesystem is strikingly slow, at least on some machines.
412411
// /usr/bin/find achieves only about 25,000 stats per second

0 commit comments

Comments
 (0)