Repository navigation
Conversation
By default, gopls type-checks every workspace package to report its
compilation errors, and it publishes diagnostics for files that are
not open. In a workspace with thousands of packages, this takes
minutes of CPU and gigabytes of memory after gopls starts. Some
clients also have no use for these diagnostics. For example, the LSP
client of an AI coding agent can add each published diagnostic to the
model's context, including diagnostics for files that the agent never
opened.
Add an experimental "diagnosticsScope" setting. The default,
"workspace", keeps the current behavior. With "openPackages", the
diagnose function type-checks only the workspace packages that
contain an open file. Analysis already uses this set of packages.
The final updateDiagnostics call publishes empty diagnostics for each
file that is not in the result. Thus gopls clears the diagnostics of
a package when its last open file closes or when the setting changes.
diagnoseChangedFiles considers only open files, so it does not change.
With "openPackages", gopls does not report errors in a package that
an edit breaks until a file of that package is open. Also, the first
references or implementation query must type-check the reverse
dependencies. With "workspace", the diagnostics pass type-checks them
in advance.
I measured the effect on a CockroachDB checkout that has about 2,500
workspace packages and 11,800 packages in total. The checkout has no
generated code, so the workspace has about 114,000 compiler errors.
The client opens one file, waits for its diagnostics, adds a type
error, removes it, and then waits 60s. Each cell shows two runs.
workspace openPackages
cold cache
peak RSS 11.4, 11.8 GB 3.3, 3.4 GB
CPU 205, 253 s 38, 39 s
warm cache
peak RSS 5.4, 1.9 GB 1.2, 1.4 GB
CPU 54, 33 s 21, 21 s
files with diagnostics 4,760 12
diagnostics 114,530 99
In one run with a 240s wait after the edit, the cold "workspace" run
used 263s of CPU and the cold "openPackages" run used 38s.
For both values, the time from didOpen to the first diagnostics for
the open file was 13-26s with a cold cache and 11-16s with a warm
cache. After an edit, diagnostics arrived in 30ms or less.
I wrote this change with Claude Code.
Updates golang/go#69523
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By default, gopls type-checks every workspace package to report its
compilation errors, and it publishes diagnostics for files that are
not open. In a workspace with thousands of packages, this takes
minutes of CPU and gigabytes of memory after gopls starts. Some
clients also have no use for these diagnostics. For example, the LSP
client of an AI coding agent can add each published diagnostic to the
model's context, including diagnostics for files that the agent never
opened.
Add an experimental "diagnosticsScope" setting. The default,
"workspace", keeps the current behavior. With "openPackages", the
diagnose function type-checks only the workspace packages that
contain an open file. Analysis already uses this set of packages.
The final updateDiagnostics call publishes empty diagnostics for each
file that is not in the result. Thus gopls clears the diagnostics of
a package when its last open file closes or when the setting changes.
diagnoseChangedFiles considers only open files, so it does not change.
With "openPackages", gopls does not report errors in a package that
an edit breaks until a file of that package is open. Also, the first
references or implementation query must type-check the reverse
dependencies. With "workspace", the diagnostics pass type-checks them
in advance.
I measured the effect on a CockroachDB checkout that has about 2,500
workspace packages and 11,800 packages in total. The checkout has no
generated code, so the workspace has about 114,000 compiler errors.
The client opens one file, waits for its diagnostics, adds a type
error, removes it, and then waits 60s. Each cell shows two runs.
In one run with a 240s wait after the edit, the cold "workspace" run
used 263s of CPU and the cold "openPackages" run used 38s.
For both values, the time from didOpen to the first diagnostics for
the open file was 13-26s with a cold cache and 11-16s with a warm
cache. After an edit, diagnostics arrived in 30ms or less.
I wrote this change with Claude Code.
Updates golang/go#69523