Skip to content

Commit

Permalink
gopls/internal/filecache: suppress gc in tests
Browse files Browse the repository at this point in the history
Now that our CI builds (have for some time) set
an explicit GOPLSCACHE, it's not necessary for
tests to run the filecache GC, and it is costly
since they all try to do so at once.

This CL rotates the main loop so the first GC
doesn't start until after 5m, by which time the
tests are done.

This improves the real time of the integration
tests on macOS by about 8%.

n=3
before: 	119 115 117 mean=117s real
after: 		104 107 111 mean=107s real

Change-Id: I5eddb850795976e4a9fde33b0fc909e3d8e87169
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588768
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
  • Loading branch information
adonovan authored and gopherbot committed Jun 3, 2024
1 parent b623539 commit 58cc8a4
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions gopls/internal/filecache/filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,6 @@ func gc(goplsDir string) {
// /usr/bin/find achieves only about 25,000 stats per second
// at full speed (no pause between items), meaning a large
// cache may take several minutes to scan.
// We must ensure that short-lived processes (crucially,
// tests) are able to make progress sweeping garbage.
//
// (gopls' caches should never actually get this big in
// practice: the example mentioned above resulted from a bug
Expand All @@ -439,6 +437,11 @@ func gc(goplsDir string) {
dirs := make(map[string]bool)

for {
// Wait unconditionally for the minimum period.
// We do this even on the first run so that tests
// don't (all) run the GC.
time.Sleep(minPeriod)

// Enumerate all files in the cache.
type item struct {
path string
Expand All @@ -459,8 +462,6 @@ func gc(goplsDir string) {
}
} else {
// Unconditionally delete files we haven't used in ages.
// (We do this here, not in the second loop, so that we
// perform age-based collection even in short-lived processes.)
age := time.Since(stat.ModTime())
if age > maxAge {
if debug {
Expand Down Expand Up @@ -503,9 +504,6 @@ func gc(goplsDir string) {
}
files = nil // release memory before sleep

// Wait unconditionally for the minimum period.
time.Sleep(minPeriod)

// Once only, delete all directories.
// This will succeed only for the empty ones,
// and ensures that stale directories (whose
Expand Down

0 comments on commit 58cc8a4

Please sign in to comment.