fix: replace os.ReadDir with fs.ReadDir(1) to avoid extra memory usage#2959
fix: replace os.ReadDir with fs.ReadDir(1) to avoid extra memory usage#2959andyzhangx merged 1 commit intomasterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andyzhangx The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
This PR optimizes memory usage in the ensureMountPoint function by replacing os.ReadDir(target) with f.ReadDir(1). The original implementation read all directory entries just to verify mount point accessibility, which could be expensive for directories with many files. The new implementation reads only a single entry, achieving the same validation purpose with significantly reduced memory footprint.
Changes:
- Added
ioimport to handleio.EOFfor empty directories - Replaced
os.ReadDir(target)withos.Open(target)followed byf.ReadDir(1) - Added proper handling for empty directories (io.EOF case)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/retest |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
fix: replace os.ReadDir with fs.ReadDir(1) to avoid extra memory usage
Which issue(s) this PR fixes:
Fixes #
Requirements:
Special notes for your reviewer:
Release note: