Skip to content
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 walk with walkdir #34251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

priyanshikhetwani
Copy link
Contributor

@priyanshikhetwani priyanshikhetwani commented Feb 2, 2025

What would you like to be added:
filepath.WalkDir where its appropriate.

Why is this needed:
To reduce unnecessary stat call.
(filepath.WalkDir uses os.DirEntry, which is more lightweight and avoids redundant stat calls, making it faster and more efficient for traversing directories when full metadata is not needed.)

Fixes: #34250

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/config Issues or PRs related to code in /config area/kubetest labels Feb 2, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @priyanshikhetwani. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 2, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: priyanshikhetwani
Once this PR has been reviewed and has the lgtm label, please assign aojea, wojtek-t for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Gofastasf
Copy link

Hey use fs.DirEntry instead of os.DirEntry.

@@ -223,7 +223,7 @@ func (t *GinkgoTester) findBinary(name string) (string, error) {
}

if bazelBinExists {
err := filepath.Walk(bazelBin, func(path string, info os.FileInfo, err error) error {
err := filepath.WalkDir(bazelBin, func(path string, info os.DirEntry, err error) error {
Copy link
Member

@BenTheElder BenTheElder Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tool is deprecated but at the same time breaking it would be a problem.

Do we really need to make this change?

Go does not remove or stop supporting deprecated methods in the standard library (this would break the Go1 promise), they just discourage new usage versus better designed utilities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aim was to remove overhead calls to os.stat since filepath.WalkDir allows us to interact with directory entries directly via os.DirEntry without needing to gather full file metadata (size, permissions, etc) , which avoids the overhead of making an additional system call (os.Stat) for each file.

But if this would break the Go1 promise, Do you want me to close this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aim was to remove overhead calls to os.stat since filepath.WalkDir allows us to interact with directory entries directly via os.DirEntry without needing to gather full file metadata (size, permissions, etc) , which avoids the overhead of making an additional system call (os.Stat) for each file.

This overhead is negligible though, isn't it? This isn't a high performance operation (also this particular codepath is effectively dead unless developing very old kubernetes releases)

But if this would break the Go1 promise, Do you want me to close this PR?

Er no, Go cannot remove the old method, so continuing to use it is safe. Us switching to a different API just requires not introducing our own bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config Issues or PRs related to code in /config area/kubetest cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use filepath.WalkDir instead of filepath.Walk
4 participants