x/tools/imports: slow due to unnecessary vendor scans #22370
Labels
FrozenDueToAge
help wanted
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
What version of Go are you using (
go version
)?go version go1.9 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
Ran
goimports -v main.go
on a very small file missing an import.What did you expect to see?
Expected the
goimports
command to run considerably faster, since on aproperly configured IDE this is ran on each file save.
What did you see instead?
Running goimports took much longer than expected. Running it several times
produces similar results, so it's not "cold".
Debugging
A one line change was made to the
x/tools/imports
package to output eachdirectory being scanned:
It turns out that most of the directories being scanned were part of external
vendor directories, which could never be imported by the current package.
All of the output was captured into a log.txt file.
With my $GOPATH, these were the findings:
In summary, there were 316k directories scanned that could have been ignored.
With a hacky local change to ignore external vendors during the scan, we saw a
significant performance improvement:
cc @prashantv
The text was updated successfully, but these errors were encountered: