scc icon indicating copy to clipboard operation
scc copied to clipboard

Performance: Use os.File.ReadDir / DirEntry to avoid stat (go 1.16+)

Open mpx opened this issue 3 years ago • 2 comments

Consider adding support for ReadDir and DirEntry (added in go1.16). This API often enables walking code to avoid stat(2) [release notes]. A small DirEntry shim could be used to continue support for older Go toolchains (without the performance improvement).

Afaict, DirectoryWalker could avoid stat for directories, and ignored/excluded paths.

This is probably only a minor speedup in the common case since os.FileInfo.Size is used for processed files. However, it could be much larger when the ratio of non-processed to processed paths in high.

mpx avatar May 11 '21 08:05 mpx

Yep pretty happy to have seen this come in. Just need to evaluate its impact on performance. Something to do for sure though.

boyter avatar May 13 '21 01:05 boyter

Seems to be much faster than most other implementations based on my tests https://engineering.kablamo.com.au/posts/2021/quick-comparison-between-go-file-walk-implementations

Ill hack in a version soon and see how it goes.

boyter avatar Oct 19 '21 01:10 boyter