Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: optimize calculation of the workspace symbol index #52602

Closed
findleyr opened this issue Apr 28, 2022 · 2 comments
Closed

x/tools/gopls: optimize calculation of the workspace symbol index #52602

findleyr opened this issue Apr 28, 2022 · 2 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@findleyr
Copy link
Contributor

Right now, the workspace symbol index is populated on the first workspace symbol request, theoretically to optimize for clients that don't use workspace symbols at all.

I recalled this taking ~5s for a large repo like Kubernetes, after which subsequent workspace symbol requests take <100ms. Seemed OK. However, testing this now it often takes 20s+ for the initial population with Kubernetes (and is surprisingly variable). We should either improve this initial performance, or eagerly populate the symbol table.

The symbol handle (which generates symbols for a file) currently bypasses the cache for the parsed file, i.e. re-parses the file, to avoid pinning the parsed file in the cache. We can probably speed up the initial symbol load significantly by supporting cache-peeking, so that we can leverage existing parsed files in memory, if they exist, without pinning.

@findleyr findleyr added this to the gopls/v0.8.4 milestone Apr 28, 2022
@findleyr findleyr self-assigned this Apr 28, 2022
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Apr 28, 2022
@findleyr
Copy link
Contributor Author

findleyr commented May 3, 2022

In https://go-review.googlesource.com/c/tools/+/403679, I update the symbolizer to

  1. Use cached parsed files if they exist.
  2. Otherwise parse as quickly as possible (skipping comments and object resolution)

With these two changes, in my experiments the initial symbol load is ~3x faster. (from ~16s for k8s to ~5s, and from 2.4s for x/tools to 700ms.

We could do more and actually pre-populate symbols, but this seems good enough for now.

If we wanted to further improve this, we could populate symbols eagerly when we type-check a package -- we have access to the full AST before we filter it.

@findleyr findleyr changed the title x/tools/gopls: pre-populate the workspace symbol index x/tools/gopls: optimize calculation of the workspace symbol index May 3, 2022
@findleyr
Copy link
Contributor Author

findleyr commented May 9, 2022

This was fixed by go.dev/cl/52602 (the referenced issue in the Fixes line should have been golang/go#NNNN).

@findleyr findleyr closed this as completed May 9, 2022
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

2 participants