Skip to content

Commit cf354b6

Browse files
anton-kuklinstamblerre
authored andcommitted
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 Change-Id: Ibe11735969eaf0cfe33024f08418e14bf71e7fc4 GitHub-Last-Rev: 67a3ccd GitHub-Pull-Request: #306 Reviewed-on: https://go-review.googlesource.com/c/tools/+/312809 Reviewed-by: Rebecca Stambler <[email protected]> Trust: Rebecca Stambler <[email protected]> Trust: Suzy Mueller <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 7657be6 commit cf354b6

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

internal/lsp/cache/snapshot.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,13 +1282,12 @@ func contains(views []*View, view *View) bool {
12821282
}
12831283

12841284
func inVendor(uri span.URI) bool {
1285-
toSlash := filepath.ToSlash(uri.Filename())
1286-
if !strings.Contains(toSlash, "/vendor/") {
1285+
if !strings.Contains(string(uri), "/vendor/") {
12871286
return false
12881287
}
12891288
// Only packages in _subdirectories_ of /vendor/ are considered vendored
12901289
// (/vendor/a/foo.go is vendored, /vendor/foo.go is not).
1291-
split := strings.Split(toSlash, "/vendor/")
1290+
split := strings.Split(string(uri), "/vendor/")
12921291
if len(split) < 2 {
12931292
return false
12941293
}
@@ -1551,7 +1550,7 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
15511550
// For internal tests, we need _test files, not just the normal
15521551
// ones. External tests only have _test files, but we can check
15531552
// them anyway.
1554-
if m.forTest != "" && !strings.HasSuffix(uri.Filename(), "_test.go") {
1553+
if m.forTest != "" && !strings.HasSuffix(string(uri), "_test.go") {
15551554
continue
15561555
}
15571556
if _, ok := result.files[uri]; ok {

0 commit comments

Comments
 (0)