-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
fs: improve ExistsSync
performance on Windows
#53537
Conversation
21d2b35
to
e2b3156
Compare
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.
Have you run the benchmarks under the benchmark folder? It’s not very reliable to benchmark a single fs call within a script using hyperfine since Node.js itself can take a lot more time to start up than doing that one fs call. (Perhaps around 40ms of that 48-47ms can be Node.js startup)
I agree. Unfortunately, I couldn't figure out some weird |
05866e2
to
a7722d0
Compare
I've opened an issue to keep track of the Windows issue I'm facing: #53538 |
This comment was marked as outdated.
This comment was marked as outdated.
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 agree with @joyeecheung that this should be benchmarked properly before being merged. (Then again, benchmarking read-only fs operations is mostly pointless since the kernel will cache all the I/O and the results will not reflect real-world performance gains.)
Especially for symlinks, we are now not executing 2 different operating-system calls, and only one.
Did you test this hypothesis, or is it guaranteed by std::filesystem::exists
?
Why would you need npm access to run the benchmarks? I think they can simply be run as
? |
Oh I see in #53538 you were trying to run (Or you could run the R version with |
It seems, this PR is 15% faster |
That only applies to the non-existing part. The question for me is what is more likely: existing or non-existing?
|
a7722d0
to
a4b05d2
Compare
@BridgeAR for unix, the difference is 15% but on Windows, but on windows, it reduces the number of OS calls. |
This comment was marked as outdated.
This comment was marked as outdated.
I was referencing the cppreference (https://en.cppreference.com/w/cpp/filesystem/exists) |
I don't see anything in that reference that would guarantee that the standard library function makes a single system call (or the Windows equivalent) and not multiple system calls. |
This comment was marked as outdated.
This comment was marked as outdated.
a4b05d2
to
5c504b8
Compare
5c504b8
to
0c05f7c
Compare
Simplifies code by using
std::filesystem
. Since std::filesystem is C++17, this pull-request can be backported to 18 and 20.The following benchmark shows 2% improvement, but I'm sure if we had a Windows benchmark-ci machine it would have better results. Especially for symlinks, we are now not executing 2 different operating-system calls, and only one.
FYI: std::filesystem::exists follows symlinks.
Benchmark code:
Benchmark result:
cc @nodejs/fs @nodejs/platform-windows