From 58cc8a4458597b256f404b4a4a84edc71cd0d00b Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 31 May 2024 17:06:04 -0400 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Auto-Submit: Alan Donovan --- gopls/internal/filecache/filecache.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gopls/internal/filecache/filecache.go b/gopls/internal/filecache/filecache.go index af917578e4f..31a76efe3ae 100644 --- a/gopls/internal/filecache/filecache.go +++ b/gopls/internal/filecache/filecache.go @@ -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 @@ -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 @@ -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 { @@ -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