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: high memory use and sluggishness #45363

Closed
bhcleek opened this issue Apr 2, 2021 · 3 comments
Closed

x/tools/gopls: high memory use and sluggishness #45363

bhcleek opened this issue Apr 2, 2021 · 3 comments
Labels
FrozenDueToAge 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.

Comments

@bhcleek
Copy link
Contributor

bhcleek commented Apr 2, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

golang.org/x/tools/gopls v0.6.9
    golang.org/x/tools/gopls@v0.6.9 h1:LBBcE2y3Tb4bp79JVLWCQBbvYCFEs5ADGWsQDoSLk1Q=

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/Users/bhcleek/go/bin"
GOCACHE="/Users/bhcleek/Library/Caches/go-build"
GOENV="/Users/bhcleek/Library/Application Support/go/env"
GOEXE=""
GOFLAGS="-mod=vendor"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/bhcleek/go/pkg/mod"
GONOPROXY="$INTERNAL_REPOS"
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/bhcleek/go"
GOPRIVATE="$INTERNAL_REPOS"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/bhcleek/src/$MODULE/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f9/d6g779t53gq_20w0zm2f_1zm0000gn/T/go-build3331311271=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Start up gopls in our monorepo in module aware mode by opening vscode or Vim w/ vim-go

What did you expect to see?

Similar memory use and performance as when using GOPATH mode.

What did you see instead?

Very high memory use and sluggishness. Using module aware mode, gopls very quickly starts using 10GB of memory or more. Other users internally report even higher memory use.

Performance is generally very sluggish. Completion requests, for example, have a noticable delay before a response is delivered.

In GOPATH mode, memory sits around 300MB and gopls is very responsive.

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Apr 2, 2021
@heschi heschi self-assigned this Apr 3, 2021
@heschi
Copy link
Contributor

heschi commented Apr 3, 2021

I'm working with @bhcleek on this privately.

@seankhliao seankhliao changed the title gopls: high memory use and sluggishness x/tools/gopls: high memory use and sluggishness Apr 3, 2021
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 3, 2021
@gopherbot gopherbot added this to the Unreleased milestone Apr 3, 2021
@stamblerre stamblerre modified the milestones: Unreleased, gopls/unplanned Apr 5, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/310170 mentions this issue: internal/lsp: introduce DegradedLowMemoryMode

gopherbot pushed a commit to golang/tools that referenced this issue Apr 23, 2021
We still hear from users for whom gopls uses too much memory. My efforts
to reduce memory usage while maintaining functionality are proving
fruitless, so perhaps it's time to accept some functionality loss.

DegradeClosed MemoryMode typechecks all packages in ParseExported mode
unless they have a file open. This should dramatically reduce memory
usage in monorepo-style scenarious, where a ton of packages are in the
workspace and the user might plausibly want to edit any of them.
(Otherwise they should consider using directory filters.)

The cost is that features that work across multiple packages...won't.
Find references, for example, will only find uses in open packages or in
the exported declarations of closed packages.

The current implementation is a bit leaky; we keep the ParseFull
packages in memory even once all their files are closed. This is related
to a general failure on our part to drop unused packages from the
snapshot, so I'm not going to try to fix it here.

Updates golang/go#45457, golang/go#45363.

Change-Id: I38b2aeeff81a1118024aed16a3b75e18f17893e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310170
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
@findleyr findleyr added the gopls/performance Issues related to gopls performance (CPU, memory, etc). label Oct 8, 2021
@heschi heschi removed their assignment Jul 11, 2022
@findleyr
Copy link
Contributor

We just cut a prerelease of gopls including a significantly different model for package information:

go install golang.org/x/tools/gopls@v0.12.0-pre.1

I believe this should significantly improve memory usage. Please let me know if it doesn't. In the meantime, this issue seems mostly redundant with https://go.dev/issue/47855, which while filed later has gained more traction. I will close this in favor of #47855, where we can track verifying that memory usage has improved.

@findleyr findleyr closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2023
@golang golang locked and limited conversation to collaborators Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

6 participants
@bhcleek @stamblerre @gopherbot @heschi @findleyr and others