githubnemo / CompileDaemon

Very simple compile daemon for Go
BSD 2-Clause "Simplified" License
1.61k stars 153 forks source link

refact: replace filepath.Walk into filepath.WalkDir #70

Closed HurSungYun closed 2 years ago

HurSungYun commented 2 years ago

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.

This change would make some performance improvements when lots of directories are matched with given flagExcludedDirs pattern.

Currently, CompileDaemon requires Go 1.11 or higher but WalkDir are introduced in Go 1.16. Thus, Go 1.16 or higher version will be needed after merging this PR.

Feel free to close this PR if you don't want to update Go version now.

githubnemo commented 2 years ago

Thanks, this seems reasonable :)