x/tools/imports: slow on relative paths #22139
Labels
FrozenDueToAge
Tools
This label describes issues relating to any tools in the x/tools repository.
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
What version of Go are you using (
go version
)?go version go1.9 linux/amd64
Does this issue reproduce with the latest release?
Yes, I reproduced after fetching latest goimports and imports.
What operating system and processor architecture are you using (
go env
)?(docker)
What did you do?
I ran
goimports -w relative/path/to/code
. We run this after a code generation step, so there are many (~150) files that need fixing by goimports. Our repo has ~1800 packages under vendor/.What did you expect to see?
I expected it to complete reasonably quickly relative to the number of files to be fixed.
What did you see instead?
It took a suspiciously long time.
CPU profile (from a different run than above):
We seem to be calling os.Getwd() a lot via filepath.Abs(). I patched imports/fix.go to "pre-abs" the provided path to avoid expensive os.Getcwd() call in filepath.Abs(), and that sped it up:
This approach probably won't help on windows since filepath.Abs() always makes a syscall. Maybe a better approach is to just reduce the calls to filepath.Abs() through some other cleverness in "imports".
The text was updated successfully, but these errors were encountered: