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 strategy for sending overlays to go/packages #32810
Comments
I probably should have used a more descriptive name than |
Ah, ok. I misunderstood what Maybe we can read the files contents in It is also weird that having any unsaved file causes us to hit the go/packages overlay code when opening any new file. Most of the time we already know a file's package path, so it seems like go/packages could avoid doing the overlay "go list" calls if the package being loaded doesn't depend on the package with an overlay file? |
I suppose we could add that check to solve the The issue with the overlays is that go/packages needs to match them to their packages to figure that part out. The way we use go/packages now, we basically ask it for all of the packages under a certain directory (that's the way |
Change https://golang.org/cl/184257 mentions this issue: |
As per discussion on golang/go#32810, to avoid the `go list` storm caused by many files being opened, we check if the file content opened is equivalent to the content on disk. If so, we mark this file as "on disk" so that we don't send it as an overlay to go/packages. Updates golang/go#32810 Change-Id: I0a520cf91bbe933c9afb76d0842f5556ac4e5b28 Reviewed-on: https://go-review.googlesource.com/c/tools/+/184257 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
I tested and the above change avoids the extra "go list" calls. Thanks! Currently gopls only passes along the overlay file names to go/packages, and it seems like the implicit assumption in go/packages is we have no idea what package those files belong to. But most of the time gopls has already loaded the package and knows what package they belong to. For example for common case:
|
I don't think there are any further optimizations we can make here. It would be too much complexity to strategically not send overlays to go/packages. |
When opening files gopls still hits the expensive go/packages "overlay" case. gopls has logic to know a file is not a pure overlay after a
DidSave
event, but when starting up, Emacs only sends a bunch ofDidOpen
events. Perhaps we should track "onDisk" from the "os.Stat" we do in (*view).findFile instead of inDidSave
?/cc @stamblerre
The text was updated successfully, but these errors were encountered: