[tools] gopls/internal/cache: try pre func before getPackageHandles in forEachPackage

2 views
Skip to first unread message

Robert Findley (Gerrit)

unread,
Apr 7, 2026, 7:12:29 PM (2 days ago) Apr 7
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Robert Findley has uploaded the change for review

Commit message

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
Change-Id: I28a233043cda63b5af26b5a0283f084a19bc1e68

Change diff

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)

Change information

Files:
  • M gopls/internal/cache/check.go
Change size: XS
Delta: 1 file changed, 7 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I28a233043cda63b5af26b5a0283f084a19bc1e68
Gerrit-Change-Number: 763860
Gerrit-PatchSet: 1
Gerrit-Owner: Robert Findley <rfin...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Robert Findley (Gerrit)

unread,
Apr 7, 2026, 7:12:52 PM (2 days ago) Apr 7
to goph...@pubsubhelper.golang.org, Alan Donovan, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Robert Findley voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I28a233043cda63b5af26b5a0283f084a19bc1e68
Gerrit-Change-Number: 763860
Gerrit-PatchSet: 1
Gerrit-Owner: Robert Findley <rfin...@golang.org>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Robert Findley <rfin...@golang.org>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Comment-Date: Tue, 07 Apr 2026 23:12:48 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Robert Findley (Gerrit)

unread,
Apr 8, 2026, 10:57:48 AM (14 hours ago) Apr 8
to goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Robert Findley voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I28a233043cda63b5af26b5a0283f084a19bc1e68
Gerrit-Change-Number: 763860
Gerrit-PatchSet: 3
Gerrit-Owner: Robert Findley <rfin...@golang.org>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Robert Findley <rfin...@golang.org>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Comment-Date: Wed, 08 Apr 2026 14:57:45 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Robert Findley (Gerrit)

unread,
Apr 8, 2026, 6:51:16 PM (6 hours ago) Apr 8
to goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Robert Findley voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I28a233043cda63b5af26b5a0283f084a19bc1e68
Gerrit-Change-Number: 763860
Gerrit-PatchSet: 5
Gerrit-Owner: Robert Findley <rfin...@golang.org>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Robert Findley <rfin...@golang.org>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Comment-Date: Wed, 08 Apr 2026 22:51:12 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages