From f74a6698e3f9792795e13fe1e0895a8cbb7c331d Mon Sep 17 00:00:00 2001 From: William Langford Date: Thu, 22 Apr 2021 12:03:26 -0400 Subject: [PATCH] internal/lsp/cache: preallocate internal maps when cloning snapshots For large codebases, the cost of copying these maps can be fairly high, especially when it needs to repeatedly grow the map's underlying storage. Preallocate these to the size of the original snapshot maps to prevent the need to grow the storage during the clone. Updates golang/go#45686 Change-Id: I4cfcd5b7cba8110e4f7e706fd9ea968aaeb6ff0c Reviewed-on: https://go-review.googlesource.com/c/tools/+/312689 Trust: Robert Findley Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Rebecca Stambler --- internal/lsp/cache/snapshot.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index d2fa8477b9..0804ad929e 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -1342,18 +1342,18 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC builtin: s.builtin, initializeOnce: s.initializeOnce, initializedErr: s.initializedErr, - ids: make(map[span.URI][]packageID), - importedBy: make(map[packageID][]packageID), - metadata: make(map[packageID]*metadata), - packages: make(map[packageKey]*packageHandle), - actions: make(map[actionKey]*actionHandle), - files: make(map[span.URI]source.VersionedFileHandle), - goFiles: make(map[parseKey]*parseGoHandle), - workspacePackages: make(map[packageID]packagePath), - unloadableFiles: make(map[span.URI]struct{}), - parseModHandles: make(map[span.URI]*parseModHandle), - modTidyHandles: make(map[span.URI]*modTidyHandle), - modWhyHandles: make(map[span.URI]*modWhyHandle), + ids: make(map[span.URI][]packageID, len(s.ids)), + importedBy: make(map[packageID][]packageID, len(s.importedBy)), + metadata: make(map[packageID]*metadata, len(s.metadata)), + packages: make(map[packageKey]*packageHandle, len(s.packages)), + actions: make(map[actionKey]*actionHandle, len(s.actions)), + files: make(map[span.URI]source.VersionedFileHandle, len(s.files)), + goFiles: make(map[parseKey]*parseGoHandle, len(s.goFiles)), + workspacePackages: make(map[packageID]packagePath, len(s.workspacePackages)), + unloadableFiles: make(map[span.URI]struct{}, len(s.unloadableFiles)), + parseModHandles: make(map[span.URI]*parseModHandle, len(s.parseModHandles)), + modTidyHandles: make(map[span.URI]*modTidyHandle, len(s.modTidyHandles)), + modWhyHandles: make(map[span.URI]*modWhyHandle, len(s.modWhyHandles)), workspace: newWorkspace, }