Skip to content

Commit e8cdaf4

Browse files
committed
gopls/internal/lsp/cache: fast-path for type-checking active packages
Partially revert CL 512636, putting back the fast path to fetch the active package. This fixes a "regression" in certain fast benchmarks, such as Definition, Hover, or References in a local package. The numbers are still small either way, but may matter in very large repos. Change-Id: Id850eaa7a2599d9fb6ad042e762b59b3d5220cf1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/513101 Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent da5abd3 commit e8cdaf4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

gopls/internal/lsp/cache/check.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,30 @@ type pkgOrErr struct {
9393
// the type-checking operation.
9494
func (s *snapshot) TypeCheck(ctx context.Context, ids ...PackageID) ([]source.Package, error) {
9595
pkgs := make([]source.Package, len(ids))
96+
97+
var (
98+
needIDs []PackageID // ids to type-check
99+
indexes []int // original index of requested ids
100+
)
101+
102+
// Check for existing active packages, as any package will do.
103+
//
104+
// This is also done inside forEachPackage, but doing it here avoids
105+
// unnecessary set up for type checking (e.g. assembling the package handle
106+
// graph).
107+
for i, id := range ids {
108+
if pkg := s.getActivePackage(id); pkg != nil {
109+
pkgs[i] = pkg
110+
} else {
111+
needIDs = append(needIDs, id)
112+
indexes = append(indexes, i)
113+
}
114+
}
115+
96116
post := func(i int, pkg *Package) {
97-
pkgs[i] = pkg
117+
pkgs[indexes[i]] = pkg
98118
}
99-
return pkgs, s.forEachPackage(ctx, ids, nil, post)
119+
return pkgs, s.forEachPackage(ctx, needIDs, nil, post)
100120
}
101121

102122
// getImportGraph returns a shared import graph use for this snapshot, or nil.

0 commit comments

Comments
 (0)