Skip to content

<filesystem>: Improve symlink_status performance - #5071

Merged
Stephan T. Lavavej (StephanTLavavej) merged 9 commits into
microsoft:mainfrom
nikola-sh:fix_symlink_status
Nov 14, 2024
Merged

<filesystem>: Improve symlink_status performance#5071
Stephan T. Lavavej (StephanTLavavej) merged 9 commits into
microsoft:mainfrom
nikola-sh:fix_symlink_status

Conversation

@nikola-sh

@nikola-sh nikola-sh commented Nov 9, 2024

Copy link
Copy Markdown
Contributor

_Get_any_status(__Path, __std_fs_stats_flags::_Attributes | __std_fs_stats_flags::_Reparse_tag) calls to many WinAPI functions for regular files or directories. It calls GetFileAttributesEx + CreateFile + GetFileInformationByHandleEx(FileBasicInfo) but GetFileAttributesEx is enough to get all needed data if it is known that a file is not a reparse point.
This problem affects symlink_status performance.

Benchmark symlink_status results before changes:

---------------------------------------------------------
Benchmark               Time             CPU   Iterations
---------------------------------------------------------
symlink_status      15376 ns        15346 ns        44800

Benchmark symlink_status results after changes:

---------------------------------------------------------
Benchmark               Time             CPU   Iterations
---------------------------------------------------------
symlink_status       2219 ns         2148 ns       320000

@nikola-sh
nikola-sh marked this pull request as ready for review November 9, 2024 19:52
@nikola-sh
nikola-sh requested a review from a team as a code owner November 9, 2024 19:52
@CaseyCarter

This comment was marked as resolved.

@azure-pipelines

This comment was marked as resolved.

Comment thread stl/src/filesystem.cpp
Comment thread benchmarks/src/filesystem.cpp
Comment thread stl/src/filesystem.cpp
Comment thread benchmarks/CMakeLists.txt Outdated
Comment thread benchmarks/src/filesystem.cpp
Comment thread benchmarks/src/filesystem.cpp
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks! On my system (5950X, 24H2, Samsung SSD 980 PRO), I observe much less of a performance improvement, but still major: 21126 ns => 10098 ns, for a speedup of 2.1x.

@nikola-sh

Copy link
Copy Markdown
Contributor Author

Thanks! On my system (5950X, 24H2, Samsung SSD 980 PRO), I observe much less of a performance improvement, but still major: 21126 ns => 10098 ns, for a speedup of 2.1x.

Thank you too!
Yes, performance improvement depends on filesystem minifilter drivers configuration.
For example, for paths on system drive GetFileAttributes works much slower than for paths from other drives.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) changed the title Improve symlink_status performance <filesystem>: Improve symlink_status performance Nov 12, 2024
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@CaseyCarter Casey Carter (CaseyCarter) removed their assignment Nov 14, 2024
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit c18bcea into microsoft:main Nov 14, 2024
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks again, and congratulations on your first microsoft/STL commit! 😻 🎉 💾

This change is expected to ship in VS 2022 17.13 Preview 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filesystem C++17 filesystem performance Must go faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants