Skip to content

Commit f74a669

Browse files
wtlangfordstamblerre
authored andcommitted
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent e435455 commit f74a669

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

internal/lsp/cache/snapshot.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -1342,18 +1342,18 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
13421342
builtin: s.builtin,
13431343
initializeOnce: s.initializeOnce,
13441344
initializedErr: s.initializedErr,
1345-
ids: make(map[span.URI][]packageID),
1346-
importedBy: make(map[packageID][]packageID),
1347-
metadata: make(map[packageID]*metadata),
1348-
packages: make(map[packageKey]*packageHandle),
1349-
actions: make(map[actionKey]*actionHandle),
1350-
files: make(map[span.URI]source.VersionedFileHandle),
1351-
goFiles: make(map[parseKey]*parseGoHandle),
1352-
workspacePackages: make(map[packageID]packagePath),
1353-
unloadableFiles: make(map[span.URI]struct{}),
1354-
parseModHandles: make(map[span.URI]*parseModHandle),
1355-
modTidyHandles: make(map[span.URI]*modTidyHandle),
1356-
modWhyHandles: make(map[span.URI]*modWhyHandle),
1345+
ids: make(map[span.URI][]packageID, len(s.ids)),
1346+
importedBy: make(map[packageID][]packageID, len(s.importedBy)),
1347+
metadata: make(map[packageID]*metadata, len(s.metadata)),
1348+
packages: make(map[packageKey]*packageHandle, len(s.packages)),
1349+
actions: make(map[actionKey]*actionHandle, len(s.actions)),
1350+
files: make(map[span.URI]source.VersionedFileHandle, len(s.files)),
1351+
goFiles: make(map[parseKey]*parseGoHandle, len(s.goFiles)),
1352+
workspacePackages: make(map[packageID]packagePath, len(s.workspacePackages)),
1353+
unloadableFiles: make(map[span.URI]struct{}, len(s.unloadableFiles)),
1354+
parseModHandles: make(map[span.URI]*parseModHandle, len(s.parseModHandles)),
1355+
modTidyHandles: make(map[span.URI]*modTidyHandle, len(s.modTidyHandles)),
1356+
modWhyHandles: make(map[span.URI]*modWhyHandle, len(s.modWhyHandles)),
13571357
workspace: newWorkspace,
13581358
}
13591359

0 commit comments

Comments
 (0)