-
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
cmd/go: mod tidy takes excessive wall & CPU time statting irrelevant files #38791
Comments
|
Taking a stack dump with go/src/cmd/go/internal/modload/search.go Line 47 in f092be8
go/src/cmd/go/internal/modload/search.go Line 156 in f092be8
go/src/cmd/go/internal/modcmd/tidy.go Line 45 in f092be8
|
Following a conversation with @bcmills, he suggests https://godoc.org/golang.org/x/tools/internal/fastwalk which avoids all the stat calls. I'm unlikely to be able to submit a patch for this, as much as I want to. I did try out fastwalk quickly (protecting 'have' with a mutex), and found there is yet another thing which does a readdir: go/src/cmd/go/internal/imports/scan.go Line 18 in f092be8
go/src/cmd/go/internal/modload/search.go Line 98 in f092be8
|
OK, I think I succeeded at testing fastwalk and using fastwalk instead of readdir. It reduces the runtime to 1s wall + 1.5 CPU + 0.9s sys. GNU I still care about the battery usage of so many go mod tidy instances in vscode, and given how many processes there are lying around to kill it seems like there is an appreciable amount of CPU time being used over time, even with my fix /cc @stamblerre on that point. |
I definitely think that commands like |
In general, we try to make all
|
(So, you may want to open a separate issue against |
If I remove the last dep on a module from my project, how would gopls use |
If you have a cached invocation of Or, you could use the change in package dependencies to trigger a |
We run it on saved changes to the |
(That is now #38816) |
The use of
It seems that the concern raised in this issue has been answered. |
@iwdgo I don't think that's expected. The @matloob Have you seen speed differences in these tests? I wonder if that's actually caused by that CL or something else? |
@jayconrod, the switch from @iwdgo, how confident are you that the improvement was observed as of CL 261537 as opposed to CL 267719? |
@bcmills I thought similarly when posting. Bisect-ing up to the root of After installing
|
Many changes later, the main performance problem seems solved on tip.
|
Sounds like this is fixed. Thanks! |
Version: go1.14.2, Repro on latest release: Yes. OS/Arch: Ubuntu 18.04 and amd64.
What did you do?
Ran
go mod tidy
on a directory wherego mod tidy
had already been run.(In the top level of a go module which also happens to be a deeply nested directory tree with millions of XML files)
What did you expect to see?
An instant result.
What did you see instead?
24s wall & 13s CPU.
Discussion
Running strace reveals that
go mod tidy
is doing a stat-like system call to every file under my directory tree, which includes very many (millions) of irrelevant xml files in a deeply nested directory tree within my go module. My expectation is that Go would ignore these files. Maybe it has to read the directory entry, to discover go files or so, but it shouldn't do more work than that.This bug currently renders vscode unusable because it frequently runs
go mod tidy
, and the net result is that I end up with hundreds of go mod tidy processes all contending to see who amongst them can stat files the fastest.My initial workaround was to run
pkill -cf 'go mod tidy'
in a loop, but @jayconrod informs me that go tooling will ignore directories beginning with_
or.
, so I will probably use that workaround for now./cc @bcmills @matloob @jayconrod
The text was updated successfully, but these errors were encountered: