Skip to content

Commit

Permalink
internal/lsp/cache: improve snapshot clone perfomance
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
anton-kuklin authored and stamblerre committed Apr 26, 2021
1 parent 7657be6 commit cf354b6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/lsp/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,13 +1282,12 @@ func contains(views []*View, view *View) bool {
}

func inVendor(uri span.URI) bool {
toSlash := filepath.ToSlash(uri.Filename())
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
}
Expand Down Expand Up @@ -1551,7 +1550,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 {
Expand Down

0 comments on commit cf354b6

Please sign in to comment.