1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:44:49 -07:00

internal/lsp/cache: fix excessive recursion in (*snapshot).clone()

It wasn't infinite, but gopls would sit at 100% cpu for ~25 seconds
whenever I made a change to a package imported by essentially
everything in my project.

Change-Id: Ifa253a4de06897260e0791888284527258e8de48
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212000
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Muir Manders 2019-12-18 17:36:47 -08:00 committed by Heschi Kreinick
parent 84f0c7cf60
commit 979b82bfef

View File

@ -516,6 +516,10 @@ func (s *snapshot) clone(ctx context.Context, withoutFile source.File) *snapshot
transitiveIDs := make(map[packageID]struct{})
var addRevDeps func(packageID)
addRevDeps = func(id packageID) {
if _, seen := transitiveIDs[id]; seen {
return
}
transitiveIDs[id] = struct{}{}
for _, rid := range s.getImportedByLocked(id) {
addRevDeps(rid)