gopls/internal/cache: try pre func before getPackageHandles in forEachPackage
For packages whose handle already has a valid key (state >= validKey),
try the pre func (typically a filecache lookup) before calling
getPackageHandles. This avoids the dependency-graph traversal in the
common steady-state case where every requested package's result is
already cached.
The existing fast path only fires for state >= validPackage (full
syntax package cached in memory). This adds a second fast path: if
the handle has a valid key and pre returns false (cache hit), the
package is skipped without building the dependency graph.
Combined with the parent CL, which makes pre's filecache lookup an
in-memory hit, this completes the steady-state fast path for
Implementations and similar queries.
Benchstat on x/tools, incremental over the parent CL (Xeon 8488C):
│ parent │ this CL │
│ sec/op │ sec/op vs base │
Implementations/tools-64 4.859m ± 13% 1.492m ± 6% -69.29% (p=0.002 n=6)
References/tools-64 3.913m ± 2% 3.854m ± 6% ~ (p=0.218 n=6+10)
WorkspaceSymbols/tools-64 7.426m ± 2% 7.654m ± 1% ~ (n=6+10)
│ cpu_seconds/op │ cpu_seconds/op vs base │
Implementations/tools-64 9.444m ± 25% 1.659m ± 42% -82.43% (p=0.002 n=6)
References/tools-64 5.941m ± 38% 4.392m ± 9% -26.07% (n=6+10)
Updates golang/go#69523
diff --git a/gopls/internal/cache/check.go b/gopls/internal/cache/check.go
index 6105d23..81a7110 100644
--- a/gopls/internal/cache/check.go
+++ b/gopls/internal/cache/check.go
@@ -144,7 +144,8 @@
indexes []int // original index of requested ids
)
- // Check for existing active packages.
+ // Check for existing active packages, or packages that can be served
+ // from the filecache without type-checking.
//
// Since gopls can't depend on package identity, any instance of the
// requested package must be ok to return.
@@ -159,6 +160,11 @@
s.mu.Unlock()
if ok && ph.state >= validPackage {
post(i, ph.pkgData.pkg)
+ } else if ok && ph.state >= validKey && pre != nil && !pre(i, ph) {
+ // The package handle has a valid key, and the pre func
+ // (typically a filecache lookup) returned false, indicating
+ // that the result was found. Skip this package entirely —
+ // no need to build the dependency graph.
} else {
needIDs = append(needIDs, id)
indexes = append(indexes, i)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |