Skip to content

Commit 58cc8a4

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/filecache: suppress gc in tests
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>
1 parent b623539 commit 58cc8a4

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

gopls/internal/filecache/filecache.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ func gc(goplsDir string) {
426426
// /usr/bin/find achieves only about 25,000 stats per second
427427
// at full speed (no pause between items), meaning a large
428428
// cache may take several minutes to scan.
429-
// We must ensure that short-lived processes (crucially,
430-
// tests) are able to make progress sweeping garbage.
431429
//
432430
// (gopls' caches should never actually get this big in
433431
// practice: the example mentioned above resulted from a bug
@@ -439,6 +437,11 @@ func gc(goplsDir string) {
439437
dirs := make(map[string]bool)
440438

441439
for {
440+
// Wait unconditionally for the minimum period.
441+
// We do this even on the first run so that tests
442+
// don't (all) run the GC.
443+
time.Sleep(minPeriod)
444+
442445
// Enumerate all files in the cache.
443446
type item struct {
444447
path string
@@ -459,8 +462,6 @@ func gc(goplsDir string) {
459462
}
460463
} else {
461464
// Unconditionally delete files we haven't used in ages.
462-
// (We do this here, not in the second loop, so that we
463-
// perform age-based collection even in short-lived processes.)
464465
age := time.Since(stat.ModTime())
465466
if age > maxAge {
466467
if debug {
@@ -503,9 +504,6 @@ func gc(goplsDir string) {
503504
}
504505
files = nil // release memory before sleep
505506

506-
// Wait unconditionally for the minimum period.
507-
time.Sleep(minPeriod)
508-
509507
// Once only, delete all directories.
510508
// This will succeed only for the empty ones,
511509
// and ensures that stale directories (whose

0 commit comments

Comments
 (0)