Skip to content

cmd/go: mod tidy takes excessive wall & CPU time statting irrelevant files #38791

Closed
@pwaller

Description

@pwaller

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 where go 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolSpeedToolsThis label describes issues relating to any tools in the x/tools repository.help wantedmodules

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions