Skip to content

cmFileSet: Fix poor performance of large file sets with export() on Windows

Exporting targets having large FILE_SETs with install(EXPORT) or export(EXPORT) currently performs poorly on Windows compared to Unix-like systems, because cmFileSet::EvaluateDirectoryEntries calls SystemTools::SameFile on every pair of parent directories in the file set. SystemTools::SameFile opens and closes two read-only filesystem handles. This causes a significant performance drop on Windows for FILE_SETs with a couple hundred files.

Use the recently added SystemTools::GetFileId function in kwsys (utils/kwsys!298 (merged)) instead of SameFile to cache the identity of a directory in cmFileSet::EvaluateDirectoryEntries. This means only one filesystem handle is needed per distinct directory path, instead of two per (even if they're equal) directory pair.

A minimal CMake project to replicate the performance problem: cmake-filesets-example.zip. During configuration, the generation step takes 0.2s with this fix versus 70s without on my development pc.

Merge request reports