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: investigate possible slowdown caused by exclusive type checking #62493

Closed
findleyr opened this issue Sep 7, 2023 · 13 comments
Closed
Assignees
Labels
gopls/performance Issues related to gopls performance (CPU, memory, etc). 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

findleyr commented Sep 7, 2023

Reported by @leitzler in slack: https://go.dev/cl/511435 may have caused increased latency in large codebases.

Needs additional investigation before the next release.

@findleyr findleyr added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/performance Issues related to gopls performance (CPU, memory, etc). labels Sep 7, 2023
@findleyr findleyr added this to the gopls/v0.14.0 milestone Sep 7, 2023
@findleyr findleyr self-assigned this Sep 7, 2023
@khanakia
Copy link

khanakia commented Sep 7, 2023

I do not have a large codebase but still, it's taking around 500ms to autocomplete

Screenshot_2023-09-07_at_3 58 00_PM

Any idea how to fix this i am using vscode

@findleyr
Copy link
Contributor Author

findleyr commented Sep 7, 2023

@khanakia can you share the rest of that trace? It looks like you are only showing the first six lines, but there should be a lot more.

Completion can take a while in very large packages, even in small codebases.

@findleyr
Copy link
Contributor Author

findleyr commented Sep 8, 2023

Thanks. From that trace I can see that type-checking is actually fast: the slowest "forEachPackage" is 50ms.

Therefore, it must simply be the completion logic that is slow, which can happen if it is formatting a very large number of results. I think we can improve this massively, by restricting the number of results and/or delaying the formatting of the completion item (using new LSP APIs).

@khanakia
Copy link

khanakia commented Sep 8, 2023

I see but vs code autocompletion takes around 300 - 500 ms to show the results in the autocomplete dropdown

The functions I am using come from this file and I do not think it is that big https://github.com/khanakia/entgo_autocomplete_vscode_slow/blob/main/ent/item_create.go

@findleyr
Copy link
Contributor Author

findleyr commented Sep 8, 2023

Understood. Thanks for sharing the example. I mean that I think we can actually fix this -- there is nothing making this unsolvable (for example type checking taking too long).

@gopherbot
Copy link

Change https://go.dev/cl/531459 mentions this issue: gopls/internal/lsp/cache: remove snapshot.typeCheckMu

@findleyr
Copy link
Contributor Author

@khanakia could you try with gopls@master? I believe you may be running into golang/go#/62665, which was just fixed.

To install gopls@master:

git clone go.googlesource.com/tools
cd tools/gopls
go install

@findleyr
Copy link
Contributor Author

@leitzler could you (1) try out master, and confirm that you still have problems, and then (2) try out https://go.dev/cl/531459, to see if it resolves your problems?

@khanakia
Copy link

khanakia commented Sep 28, 2023

It's way better now auto completion requests are around 110ms for my code base.

@findleyr Thank you very much. I really appreciate for fixing this.

@leitzler
Copy link
Contributor

Yes! It still exist in master (a slightly old one - 4b34fbf5f10d) where I see multiple calls taking more than 2 seconds.
Applying CL 531459 solves the issue completely, those calls now takes <20ms.
Thank you!

@findleyr
Copy link
Contributor Author

@khanakia that's good to hear. Thanks for confirming!

@leitzler thanks, it looks like that commit includes https://go.dev/cl/530599, which is what I wanted to check.

Ok, looks like my small CPU optimization was a major latency regression. I'll submit the revert. Glad we caught this before releasing -- thanks!

@erdauletbatalov
Copy link

Hello @findleyr, I recently got a bug because of your latest gopls version https://github.com/golang/tools/releases/tag/gopls%2Fv0.14.0-pre.1
It causes to code colorization provided by go nightly to disappear. I got used to it because it is very handy. Noticed when I go back to gopls v0.13.2 this feature shows again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/performance Issues related to gopls performance (CPU, memory, etc). 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

5 participants