Skip to content

SystemTools: Optimize GetCasePathName

This optimizes the current hotspot of CMake on Windows, previously complained about in cmake/cmake#20214 (closed). By using GetFinalPathNameByHandleW to get the actual path directly, instead of calling FindFirstFileW for every path component, I could significantly improve the speed of CMake on Windows. GetFinalPathNameByHandleW obviously doesn't work on non existing paths, which GetCasePathName still has to support, so it still needs to "walk up" the path components until it finds the first one that exist, which makes it still a bit slow and the implementation additionally more complex. This is however still significantly faster, since the majority of paths passed exist.

Before:

Benchmark 1: .\out\build\msvc-release\bin\cmake.exe -G Ninja -B build-perf -DCMAKE_BUILD_TYPE=Debug
  Time (mean ± σ):     18.728 s ±  0.047 s    [User: 0.002 s, System: 0.001 s]
  Range (min … max):   18.673 s … 18.819 s    10 runs

After:

Benchmark 1: .\out\build\msvc-release\bin\cmake.exe -G Ninja -B build-perf -DCMAKE_BUILD_TYPE=Debug
  Time (mean ± σ):     17.136 s ±  0.057 s    [User: 0.002 s, System: 0.001 s]
  Range (min … max):   17.050 s … 17.226 s    10 runs

Merge request reports

Loading