Skip to content

Commit

Permalink
internal/lsp/cache: only clone metadata if something changed
Browse files Browse the repository at this point in the history
We with immutable metadata, we don't need to clone if nothing was
invalidated.

Benchmark (didChange in k8s): 65ms->45ms

For golang/go#45686

Change-Id: I6b5e764c53a35784fd8c7b43bc26361f4ee8d928
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340853
Run-TryBot: Robert Findley <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
gopls-CI: kokoro <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
findleyr committed Jun 16, 2022
1 parent 4ba3d22 commit dffd645
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/lsp/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2016,8 +2016,15 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
}
}

result.meta = s.meta.Clone(metadataUpdates)
result.workspacePackages = computeWorkspacePackages(result.meta)
if len(metadataUpdates) > 0 {
result.meta = s.meta.Clone(metadataUpdates)
result.workspacePackages = computeWorkspacePackages(result.meta)
} else {
// No metadata changes. Since metadata is only updated by cloning, it is
// safe to re-use the existing metadata here.
result.meta = s.meta
result.workspacePackages = s.workspacePackages
}

// Inherit all of the go.mod-related handles.
for _, v := range result.modTidyHandles {
Expand Down

0 comments on commit dffd645

Please sign in to comment.