-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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/go/packages: Unusably slow when there are packages using cgo in the list #29427
Comments
cc @matloob |
#29371 is relevant. Does this reproduce at tip with that bug fixed? There's probably still a discussion to be had, but I imagine it'd be less urgent if it didn't happen every time. |
Actually, never mind; that issue was specific to |
I'm not sure if this is because of cgo, or if it's just more noticeable because it takes so long to build cgo packages. I investigated by doing some go lists on a clean cache.
I would have expected the second command to reuse cached results from the first, but it doesn't. Doing a build manually puts things in the cache and the last list is fast. Seems like a bug to me. |
This is quite bad. Loading SSA for a package takes more than 1.5 hours. See referenced issue above. |
I don't know what's going on in @klauspost's bug but it's not this one. |
Some analysis:
I think this largely has the same root cause as #29371, so maybe this should be closed. However, I think it would be interesting to discuss whether go/packages could be invoked in a way that doesn't require cgo. cc @matloob |
I'm working on a change (https://go-review.googlesource.com/c/tools/+/162140) that will allow tool to specify that they don't need the CompiledGoFiles field. Once that change is in, if a tool doesn't request CompiledGoFiles, or other Package struct fields that need compiled files, go/packages will invoke go list without -compiled. |
Change https://golang.org/cl/162140 mentions this issue: |
The options are all unexported, and this CL is (almost) a no-op: the one difference is that since needImports and needSyntax are now independently specified, LoadSyntax and LoadAllSyntax are equivalent, because LoadSyntax needs both the needImports and needSyntax bits. I want to pin down the options that we want to split into, and future CLs can allow the options to be used individually... Updates golang/go#29429 Updates golang/go#29427 Change-Id: I5b2913e2c53e7ade56905e46912b076ccc339827 Reviewed-on: https://go-review.googlesource.com/c/tools/+/162140 Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Cottrell <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
cc @matloob: is there anything else to do for this issue? It sounds like after https://golang.org/cl/162140, cgo is not always needed, but when it is needed, it still takes a long time. |
As an example, a small project that is using cgo (via sqlc) running:
resulted in:
But for some reason this is speedy:
and results in:
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried using a Go tool that uses
golang.org/x/go/tools/packages
under the hood (Specificallygogetdoc
, but many more tools are going to use it in order to support Go modules). Sincepackages
unconditionally callsgo list -compiled
(go/tools/go/packages/golist.go:630), when there are large cgo modules anywhere on the module list,packages
will cause them to be compiled, without any caching. This can take a very long time and makes any tool doing so unusably slow.Steps to reproduce
You need to have ImageMagick available. (See https://github.com/gographics/imagick)
main.go
in a new go package directory:dep init
/go get
/whatever.gogetdoc -pos main.go:#87
.What did you expect to see?
The tool works fast.
What did you see instead?
It's extremely slow, to the point of being unusable.
Related issues
zmb3/gogetdoc#47
microsoft/vscode-go#667
microsoft/vscode-go#1025
rogpeppe/godef#103
cc @zmb3 @ramya-rao-a
The text was updated successfully, but these errors were encountered: