Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use fstat instead of stat in libstd/fs.rs initial_buffer_size #47519

Closed
alex opened this issue Jan 17, 2018 · 1 comment
Closed

Use fstat instead of stat in libstd/fs.rs initial_buffer_size #47519

alex opened this issue Jan 17, 2018 · 1 comment

Comments

@alex
Copy link
Member

alex commented Jan 17, 2018

Follow up to #47324. Instead of calling stat and then open, do open and then fstat.

In my tests on macOS this is significantly faster.

@alex
Copy link
Member Author

alex commented Jan 17, 2018

Quick microbenchmark which demonstrates the performance difference; it's not in Rust, but I believe it demonstrates the underlying idea here. Measured on macOS 10.13.2:

~ ❯❯❯ python -mtimeit -s "import os; f = open('/dev/zero')" "os.fstat(f.fileno())"
1000000 loops, best of 3: 1.88 usec per loop
~ ❯❯❯ python -mtimeit -s "import os; f = open('/dev/zero')" "os.fstat(f.fileno())"
100000 loops, best of 3: 1.91 usec per loop
~ ❯❯❯ python -mtimeit -s "import os; f = open('/dev/zero')" "os.fstat(f.fileno())"
1000000 loops, best of 3: 1.91 usec per loop
~ ❯❯❯
~ ❯❯❯
~ ❯❯❯
~ ❯❯❯ python -mtimeit -s "import os; f = open('/dev/zero')" "os.stat('/dev/zero')"
100000 loops, best of 3: 3.69 usec per loop
~ ❯❯❯ python -mtimeit -s "import os; f = open('/dev/zero')" "os.stat('/dev/zero')"
100000 loops, best of 3: 3.65 usec per loop
~ ❯❯❯ python -mtimeit -s "import os; f = open('/dev/zero')" "os.stat('/dev/zero')"
100000 loops, best of 3: 3.78 usec per loop

mbrubeck added a commit to mbrubeck/rust that referenced this issue Jan 17, 2018
This replaces a `stat` syscall with `fstat` or similar, which can be
faster.  Fixes rust-lang#47519.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 17, 2018
Use File::metadata instead of fs::metadata to choose buffer size

This replaces a `stat` syscall with `fstat` or similar, which can be faster.  Fixes rust-lang#47519.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant