$ the-wire · showcase
cmd/goimports skips an lstat per file
By RepoJournal · Filed · About Go
goimports ships a hidden performance win: cmd/goimports now uses filepath.WalkDir instead of filepath.Walk, cutting one lstat per directory entry.
cmd/goimports switched from filepath.Walk to filepath.WalkDir [1]. Because the callback only needs the entry name and directory flag, the old Walk's per-entry lstat was pure overhead; WalkDir's fs.DirEntry avoids it. The change lands in golang/tools and does not alter goimports' output or command-line interface. Expect a modest speedup in directory traversal for large trees, with no behavioral change. The commit, reviewed on the Go Gerrit instance, is a small, safe dependency update for anyone tracking tools at tip.
Action items
- → Monitor the next golang/tools release for the goimports WalkDir change golang/tools [monitor]
References
- [1] cmd/goimports: use filepath.WalkDir instead of filepath.Walk ↗ golang/tools