You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go 1.16 added filepath.WalkDir alongside filepath.Walk for performance reasons (see golang/go#42027). In my experience, traversing a big network share to retrieve few files based on their name, I got a huge speedup.
From Go 1.16 docs:
Walk is less efficient than WalkDir, introduced in Go 1.16, which avoids calling os.Lstat on every visited file or directory.
The differences between WalkDirFunc compared to filepath.WalkFunc are:
The second argument has type fs.DirEntry instead of fs.FileInfo.
The function is called before reading a directory, to allow SkipDir to bypass the directory read entirely.
If a directory read fails, the function is called a second time for that directory to report the error.
filepath.Walk was not deprecated, but I think filepath.WalkDir should always be preferred: even when using the information not present in fs.DirEntry, you could save time calling os.Stat only when needed.
So I propose to add a check to suggest the use of filepath.WalkDir instead of filepath.Walk.
The text was updated successfully, but these errors were encountered:
I don't think we can make this suggestion, as it doesn't fit into any of the categories of checks. Using Walk is not a bug, nor always inferior to using WalkDir either in performance or simplicity, namely when all stats are required. That excludes all of SA and S. And I don't think that "never use filepath.Walk" would make for a good general style rule, thus excluding ST.
Go didn't deprecate filepath.Walk, and I feel like we shouldn't overrule this decision by flagging uses of filepath.Walk anyway.
This would be the kind of rule that an organisation would have to decide on and implement themselves.
Go 1.16 added
filepath.WalkDir
alongsidefilepath.Walk
for performance reasons (see golang/go#42027). In my experience, traversing a big network share to retrieve few files based on their name, I got a huge speedup.From Go 1.16 docs:
filepath.Walk was not deprecated, but I think filepath.WalkDir should always be preferred: even when using the information not present in fs.DirEntry, you could save time calling os.Stat only when needed.
So I propose to add a check to suggest the use of filepath.WalkDir instead of filepath.Walk.
The text was updated successfully, but these errors were encountered: