From e6f98923479c80d47596a050ab803568f11ebb4b Mon Sep 17 00:00:00 2001 From: Anton Kuklin Date: Thu, 22 Apr 2021 22:42:14 +0300 Subject: [PATCH 1/3] internal/lsp/cache: improve snapshot clone perfomance The existing implementation uses a lot of URI.Filename() calls, which are pretty expensive. Moreover, these calls are not necessary, as long as all the actions could be done with the raw URI string. This patch removes such calls and uses simple string casts. Updates golang/go#45686 --- internal/lsp/cache/snapshot.go | 4 ++-- internal/lsp/cache/workspace.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 28d04491f57..d217b513c9c 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -1279,7 +1279,7 @@ func contains(views []*View, view *View) bool { } func inVendor(uri span.URI) bool { - toSlash := filepath.ToSlash(uri.Filename()) + toSlash := filepath.ToSlash(string(uri)) if !strings.Contains(toSlash, "/vendor/") { return false } @@ -1548,7 +1548,7 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC // For internal tests, we need _test files, not just the normal // ones. External tests only have _test files, but we can check // them anyway. - if m.forTest != "" && !strings.HasSuffix(uri.Filename(), "_test.go") { + if m.forTest != "" && !strings.HasSuffix(string(uri), "_test.go") { continue } if _, ok := result.files[uri]; ok { diff --git a/internal/lsp/cache/workspace.go b/internal/lsp/cache/workspace.go index 6b62d2951c6..9b75f156518 100644 --- a/internal/lsp/cache/workspace.go +++ b/internal/lsp/cache/workspace.go @@ -326,7 +326,7 @@ func (w *workspace) invalidate(ctx context.Context, changes map[span.URI]*fileCh // here. if result.moduleSource != goplsModWorkspace { for uri, change := range changes { - if !isGoMod(uri) || !source.InDir(result.root.Filename(), uri.Filename()) { + if !isGoMod(uri) || !source.InDir(string(result.root), string(uri)) { continue } changed = true From 27c804cfec9b2f5b151deb58a4c8eb9c981e480f Mon Sep 17 00:00:00 2001 From: Anton Kuklin Date: Fri, 23 Apr 2021 00:32:43 +0300 Subject: [PATCH 2/3] move back Filename() for inDir comparasion --- internal/lsp/cache/workspace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/lsp/cache/workspace.go b/internal/lsp/cache/workspace.go index 9b75f156518..6b62d2951c6 100644 --- a/internal/lsp/cache/workspace.go +++ b/internal/lsp/cache/workspace.go @@ -326,7 +326,7 @@ func (w *workspace) invalidate(ctx context.Context, changes map[span.URI]*fileCh // here. if result.moduleSource != goplsModWorkspace { for uri, change := range changes { - if !isGoMod(uri) || !source.InDir(string(result.root), string(uri)) { + if !isGoMod(uri) || !source.InDir(result.root.Filename(), uri.Filename()) { continue } changed = true From 67a3ccdf30a6a99bc1b5a8e9cd2a7c0865d894d0 Mon Sep 17 00:00:00 2001 From: Anton Kuklin Date: Sun, 25 Apr 2021 21:54:31 +0300 Subject: [PATCH 3/3] removed unnecessary ToSlash usage for URI --- internal/lsp/cache/snapshot.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index d217b513c9c..b67af1dfe56 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -1279,13 +1279,12 @@ func contains(views []*View, view *View) bool { } func inVendor(uri span.URI) bool { - toSlash := filepath.ToSlash(string(uri)) - if !strings.Contains(toSlash, "/vendor/") { + if !strings.Contains(string(uri), "/vendor/") { return false } // Only packages in _subdirectories_ of /vendor/ are considered vendored // (/vendor/a/foo.go is vendored, /vendor/foo.go is not). - split := strings.Split(toSlash, "/vendor/") + split := strings.Split(string(uri), "/vendor/") if len(split) < 2 { return false }