GetCasePathName is extremely slow on Windows
The large project at my company is taking about 150 seconds in CMake configure phase (not the generation phase).
Running the Visual Studio CPU profiler indicates SystemToolsStatic::GetCasePathName
is taking about 40% of the CPU time.
After replacing this function with one returns the input as-is (essentially forcing windows being case-sensitive), the cmake configure time have been improved dramatically into 92 seconds!
std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn)
{
return pathIn;
// Hot spot in the code is
// HANDLE hFind = ::FindFirstFileW(Encoding::ToWide(test_str).c_str(), &findData);
}
In my case, the GetCasePathName
function is called from get_filename_component(ABSOLUTE|RELATIVE_PATH)
file(RELATIVE_PATH)
and add_custom_command
. And there are much more use case there.
A similar performance issue have been reported on #20203 (closed)
Potential solution:
- Add a new Policy to make cmake on Windows case sensitive.
This may cause files in
add_custom_command
only with case-different being treated as different file on Windows. In my project, the code is platform-independent, where we ensure everything is case-sensitive for Linux/Mac, thus losing the case-insensitive-ness is not a blocker. And we will be glad to buy a 40% speedup with that. - Try some new implementation like GetLongPathNameW