go/internal/lsp
Alan Donovan 9651276d64 internal/lsp/cache: optimize Snapshot.clone
This change replaces the single large map used for snapshot.goFiles
by a map of 256 stripes, each of which becomes immutable once shared.
This optimizes the common case in which the copy is nearly identical
to the original.

We still need to visit each map entry to see whether it needs to be
deleted (which is rare) and to inherit the handle in the usual case.
This is now done concurrently.

Also, share the (logically immutable) []PackageIDs slices across
old and new snapshots. This was worth 5% of CPU and 1/3 of allocations
(all small).

Benchmark on darwin/arm64 shows a 29% reduction for DidChange.

$ go test -v ./gopls/internal/regtest/bench -run=TestBenchmarkDidChange -didchange_dir=$HOME/w/kubernetes -didchange_file=pkg/util/hash/hash.go

Before:
BenchmarkStatistics	     100	  22955469 ns/op	11308095 B/op	   47412 allocs/op
BenchmarkStatistics	     100	  23454630 ns/op	11226742 B/op	   46882 allocs/op
BenchmarkStatistics	     100	  23618532 ns/op	11258619 B/op	   47068 allocs/op

After goFilesMap:
BenchmarkStatistics	     100	  16643972 ns/op	 8770787 B/op	   46238 allocs/op
BenchmarkStatistics	     100	  17805864 ns/op	 8862926 B/op	   46762 allocs/op
BenchmarkStatistics	     100	  18618255 ns/op	 9308864 B/op	   49776 allocs/op

After goFilesMap and ids sharing:
BenchmarkStatistics          100          16703623 ns/op         8772626 B/op      33812 allocs/op
BenchmarkStatistics          100          16927378 ns/op         8529491 B/op      32328 allocs/op
BenchmarkStatistics          100          16632762 ns/op         8557533 B/op      32497 allocs/op

Also:
- Add comments documenting findings of profiling.
- preallocate slice for knownSubdirs.
- remove unwanted loop over slice in Generation.Inherit

Updates golang/go#45686

Change-Id: Id953699191b8404cf36ba3a7ab9cd78b1d19c0a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/410176
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-06-10 17:57:19 +00:00
..
analysis internal: remove unneeded FileSets 2022-06-06 20:47:10 +00:00
browser all: replace all usages of os/exec with golang.org/x/sys/execabs 2021-01-19 22:25:03 +00:00
bug internal/lsp: add missing bug reporting, and panic during marker tests 2022-05-31 14:14:38 +00:00
cache internal/lsp/cache: optimize Snapshot.clone 2022-06-10 17:57:19 +00:00
cmd internal/lsp: initial test set up for inlay hints 2022-06-09 20:27:29 +00:00
command gopls/internal/vulncheck: copy logic of govulncheck -html 2022-05-12 21:17:31 +00:00
debug internal/lsp/bug: add a package for bug reporting 2022-05-16 14:45:30 +00:00
diff internal/span: eliminate TokenConverter 2022-06-01 19:19:15 +00:00
fake gopls: remove usage of golang.org/x/xerrors 2022-04-20 15:33:22 +00:00
fuzzy gopls, internal/lsp: gofmt 2022-04-12 17:41:31 +00:00
helper internal/lsp/protocol: update LSP definitions and stubs 2021-10-05 16:44:45 +00:00
lsppos internal/lsp: factor out go/token wrapper into a safetoken package 2022-05-09 17:03:37 +00:00
lsprpc internal/lsp/regtest: don't run the connection on the test context 2022-06-10 12:48:42 +00:00
mod internal/lsp/mod: fix broken assumptions about file base 2022-06-01 22:04:06 +00:00
progress internal/lsp/progress: detach context for all progress notifications 2022-06-02 20:26:04 +00:00
protocol internal/lsp/mod: fix broken assumptions about file base 2022-06-01 22:04:06 +00:00
regtest internal/lsp/regtest: don't run the connection on the test context 2022-06-10 12:48:42 +00:00
safetoken internal/span: eliminate TokenConverter 2022-06-01 19:19:15 +00:00
snippet lsp/completion: fix literal completions with type params 2022-04-26 02:30:39 +00:00
source internal/lsp/cache: optimize Snapshot.clone 2022-06-10 17:57:19 +00:00
template internal/lsp: fix source.CompareDiagnostic asymmetry 2022-05-11 17:43:03 +00:00
testdata internal/lsp: initial test set up for inlay hints 2022-06-09 20:27:29 +00:00
tests internal/lsp: initial test set up for inlay hints 2022-06-09 20:27:29 +00:00
work internal/lsp/source: eliminate ColumnMapper.PointSpan in favor of Pos 2022-06-01 19:19:59 +00:00
README.md internal/lsp: add READMEs that describe tests, how to run tests 2020-12-03 17:03:53 +00:00
call_hierarchy.go internal/lsp: release resources for call hierarchy file requests 2020-08-07 21:04:51 +00:00
code_action.go gopls: remove usage of golang.org/x/xerrors 2022-04-20 15:33:22 +00:00
code_lens.go internal/lsp: honor the file kind provided by clients for overlays 2022-01-13 20:54:45 +00:00
command.go internal/lsp/progress: detach context for all progress notifications 2022-06-02 20:26:04 +00:00
completion.go internal/lsp/source: remove workaround for newline terminated files 2022-06-01 15:40:59 +00:00
completion_test.go internal/lsp/completion: move postfix completions behind option 2021-03-29 18:55:49 +00:00
debounce.go internal/lsp: adopt bcmills' suggestion for an improved debouncer API 2021-07-13 16:40:23 +00:00
debounce_test.go internal/lsp: adopt bcmills' suggestion for an improved debouncer API 2021-07-13 16:40:23 +00:00
definition.go internal/lsp: use the correct converter for mapped range offsets 2022-06-01 15:32:54 +00:00
diagnostics.go internal/lsp/progress: detach context for all progress notifications 2022-06-02 20:26:04 +00:00
folding_range.go all: add copyright notices to files that are missing them 2021-01-06 17:23:47 +00:00
format.go internal/lsp: add support for formatting go.work files 2022-02-15 17:15:32 +00:00
general.go internal/lsp/progress: detach context for all progress notifications 2022-06-02 20:26:04 +00:00
highlight.go internal/lsp: honor the file kind provided by clients for overlays 2022-01-13 20:54:45 +00:00
hover.go internal/lsp: add hover for go.work use statements 2022-03-04 19:55:36 +00:00
implementation.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
link.go internal/span: eliminate TokenConverter 2022-06-01 19:19:15 +00:00
lsp_test.go internal/lsp: initial test set up for inlay hints 2022-06-09 20:27:29 +00:00
references.go internal/lsp: honor the file kind provided by clients for overlays 2022-01-13 20:54:45 +00:00
rename.go internal/lsp: use placeholders with prepare rename 2022-02-15 00:29:01 +00:00
reset_golden.sh
semantic.go internal/lsp/mod: fix broken assumptions about file base 2022-06-01 22:04:06 +00:00
server.go internal/lsp/progress: detach context for all progress notifications 2022-06-02 20:26:04 +00:00
server_gen.go internal/lsp/progress: detach context for all progress notifications 2022-06-02 20:26:04 +00:00
signature_help.go internal/lsp: update to latest version of LSP protocol 2021-02-02 11:32:59 +00:00
symbols.go internal/lsp: honor the file kind provided by clients for overlays 2022-01-13 20:54:45 +00:00
text_synchronization.go internal/lsp/progress: detach context for all progress notifications 2022-06-02 20:26:04 +00:00
workspace.go gopls: remove usage of golang.org/x/xerrors 2022-04-20 15:33:22 +00:00
workspace_symbol.go internal/lsp/source: add a new symbolStyle configuration option 2020-06-26 17:13:37 +00:00

README.md

lsp

internal/lsp provides much of the Language Server Protocol (lsp) implementation for gopls.

Documentation for users and contributors can be found in the gopls/doc directory.