Using mimalloc to speed up CMake on Windows
CMake on Windows is not as fast as on Linux / macOS. I guess it has to do with file system, and other factors.
By using mimalloc v1.22 I was able to get CMake master running on a Qt Creator build directory from an average of 22.20 seconds to an average of 16.66 seconds. That like 24.95% faster.
That was for MSVC 2017 64bit CMake build.
Mimalloc has a BSD license, and comes with a CMake project.
The changes I had to do to CMake were:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index da99a6ee8d..658841b2f1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -630,6 +630,11 @@ macro (CMAKE_BUILD_UTILITIES)
message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
endif()
endif()
+
+ #---------------------------------------------------------------------
+ # mimalloc
+ add_subdirectory(Utilities/mimalloc)
+
endmacro ()
#-----------------------------------------------------------------------
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index ff313d66d1..c49984e4b0 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -1128,7 +1128,7 @@ endif()
# Build CMake executable
add_executable(cmake cmakemain.cxx cmcmd.cxx cmcmd.h ${MANIFEST_FILE})
list(APPEND _tools cmake)
-target_link_libraries(cmake CMakeLib)
+target_link_libraries(cmake CMakeLib mimalloc)
add_library(CMakeServerLib
cmConnection.h cmConnection.cxx
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 5579ae16e9..fc8ffdfb8b 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -33,6 +33,8 @@
# include "cmsys/ConsoleBuf.hxx"
#endif
+#include <mimalloc.h>
+
namespace {
#ifndef CMAKE_BOOTSTRAP
const char* cmDocumentationName[][2] = {
@@ -673,6 +675,7 @@ int do_open(int ac, char const* const* av)
int main(int ac, char const* const* av)
{
+ mi_version();
cmSystemTools::EnsureStdPipes();
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
// Replace streambuf so we can output Unicode to console
And in the binary dir I had to copy mimalloc.dll
and mimalloc-redirect.dll
which are 70 KiB, and 55 KiB in size.
I think CMake should take advantage of this speed up and use mimalloc!