-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v4: all: consider io/fs changes to our APIs #630
Comments
And add fileutil.CouldBeScript2 to take advantage of fs.DirEntry. Using benchcmd with "shfmt -l ." on dozens of large git repos, we can see that avoiding stat syscalls while walking saves time: name old time/op new time/op delta ShfmtGitRepos 892ms ± 2% 778ms ± 1% -12.80% (p=0.000 n=10+7) name old user-time/op new user-time/op delta ShfmtGitRepos 699ms ±12% 628ms ±11% -10.05% (p=0.007 n=10+10) name old sys-time/op new sys-time/op delta ShfmtGitRepos 403ms ±17% 339ms ±10% -16.08% (p=0.001 n=10+9) name old peak-RSS-bytes new peak-RSS-bytes delta ShfmtGitRepos 33.5MB ± 5% 32.2MB ± 3% -3.93% (p=0.006 n=9+8) Most end users should thus see a moderate speed-up of about 10%. Updates #630.
I'm leaving this issue open for v4. For example, 4c03448 left a TODO for expand.Config, since its API came before the fs package. We can't break v3 APIs, and I don't think I'm in a rush to deprecate many v3 APIs just for the sake of small performance gains. The fileutil addition in the commit above is slightly different, because the performance does matter for shfmt. |
Notes for future reference: we tried to add an io/fs handler to the interpreter in v3 in #799, but we gave up due to the shortcomings of the current io/fs API - it doesn't support writing files, and it doesn't support a root FS on Windows, in the sense of being able to use absolute paths with their volume names. |
The interpreter has interfaces for all OS interactions except stat-ing files. Add a new handler, noting that we need both Stat and Lstat. See #630.
Once Go 1.17 is out, we'll be able to drop support for Go 1.15. Then we'll be able to use the new APIs in Go 1.16, such as the
fs.FS
interface, the fasterfilepath.WalkDir
, and so on. At least, we should be able to makeshfmt
's directory walking faster (fewer stat calls), and possibly parts ofexpand
andinterp
too.The text was updated successfully, but these errors were encountered: