-
Notifications
You must be signed in to change notification settings - Fork 4.1k
*: replace os.FileInfo with os.DirEntry where possible #157257
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
*: replace os.FileInfo with os.DirEntry where possible #157257
Conversation
stevendanna
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder: Would it be worth following up with a few of these callsites to see if they need to use this function at all?
I checked 2 of the call site and it appeared they only called Name() and IsDir() on the resulting FileInfo. Name and IsDir is available from the DirEntry's returned by the os.ReadDir call, so we could save some extra stat calls.
|
@stevendanna, right, that's a good catch. I think I can do that clean-up as a follow-up for the |
stevendanna
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 This is a nice cleanup even without the follow-up.
3ed0d4a to
5274559
Compare
|
@stevendanna I pushed another commit following this suggestion: #157257 (review). This change makes |
stevendanna
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for following up!
Previously, in a few places, we converted os.DirEntry to os.FileInfo by calling entry.Info(), which triggers a stat syscall for each entry. Most callers only needed the entry name, which is directly available from os.DirEntry via Name(). This patch switches to os.DirEntry throughout the codebase, avoiding unnecessary stat syscalls. In the few places where file size or mode is needed, we now call Info() only when required. Epic: none Release note: None Fixes: none
5274559 to
f663a2c
Compare
|
TFTR! bors r=stevendanna |
Previously, in a few places, we converted os.DirEntry to os.FileInfo by
calling entry.Info(), which triggers a stat syscall for each entry.
Most callers only needed the entry name, which is directly available from
os.DirEntry via Name(). This patch switches to os.DirEntry throughout the
codebase, avoiding unnecessary stat syscalls. In the few places where file
size or mode is needed, we now call Info() only when required.
Epic: none
Release note: None
Fixes: none