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

Calling .metadata() just for .is_{file,dir,symlink} when DirEntry is available #12955

Open
cdown opened this issue Jun 18, 2024 · 2 comments
Open
Labels
A-lint Area: New lints

Comments

@cdown
Copy link
Contributor

cdown commented Jun 18, 2024

What it does

At Meta internally I've been working on performance optimisations for a number of our widely deployed Rust daemons. One pattern I have repeatedly seen and optimised is:

    for entry in read_dir(".")? {
        entry?.metadata()?.is_dir();
    }

This requires an additional statx() (or equivalent) syscall. In some cases I have saved very large amounts of CPU and IO by just changing to:

    for entry in read_dir(".")? {
        entry?.file_type()?.is_dir();
    }

...which just uses the DT_* returned from readdir().

I plan to implement a lint which detects cases like this (where metadata() is called on entry only to call .is_{file,dir,symlink}().

Does this sound reasonable?

Advantage

  • Reduced CPU instructions
  • Reduced IO cost

Drawbacks

No response

Example

See above description.

@cdown cdown added the A-lint Area: New lints label Jun 18, 2024
@Alexendoo
Copy link
Member

Yeah that sounds great

@cdown
Copy link
Contributor Author

cdown commented Jun 19, 2024

Thanks! I'll get to work then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants