Cmake 4.0.0 is being slower than previous versions

I’m running CMake 4.0.0 on identical settings as I was doing with CMake 3.31.6 and all the configure times in my projects are equal or worse than before. After doing some profiling, most of it looks identical except some find_package calls. For example this call:

find_package(Boost 1.70 CONFIG REQUIRED system filesystem regex fiber
  thread python unit_test_framework program_options log log_setup graph)

goes from around 30 ms to more than 70 ms, that’s more than double and in general all calls are equal or worse, with the worst cases being 2x slower or even more.

I’m using the cmake that is available on Arch Linux. I have checked that it doesn’t seem the build options have changed, so I think this may be caused by cmake itself.

To reproduce for Boost, create a CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(BoostTest)
find_package(Boost 1.70 CONFIG REQUIRED system filesystem regex fiber
  thread python unit_test_framework program_options log log_setup graph)

And then run:

mkdir build && cd build
cmake .. --profiling-format=google-trace --profiling-output=prof -G Ninja

And then open in google chrome in about:tracing.

The following benchmarks was run on CMake 3.31.6 and CMake 4.0.0 snap packages on Ubuntu.

  1. Large CMake-based project with approximately ~100 find_package() invocations done in the configuration phase:

    CMake 3.31.6:

    -- Configuring done (30.2s)
    -- Generating done (1.0s)
    
    -- Configuring done (30.4s)
    -- Generating done (1.0s)
    
    -- Configuring done (30.1s)
    -- Generating done (1.0s)
    

    CMake 4.0.0:

    -- Configuring done (30.8s)
    -- Generating done (1.1s)
    
    -- Configuring done (30.6s)
    -- Generating done (1.1s)
    
    -- Configuring done (30.5s)
    -- Generating done (1.1s)
    
  2. A very complex command-line CMake-based script tokenizing ~4000 lines of CMake code running it 3-times:

    CMake 3.31.6:

    7.017641 sec
    6.892121 sec
    6.910700 sec
    

    CMake 4.0.0:

    7.040688 sec
    6.926531 sec
    7.007777 sec
    

I would say, the performance is completely the same in my case. There might be a slight deviation here and there due to other tasks running locally - browser/music etc. Difficult to say something concrete for every case out there though.

Thanks Peter for the numbers. What I see however is that when configuring with CMake 4.0.0 it is always equal or slower, which agrees with what I saw. It’s not a lot but I would like if performance doesn’t get worse. Reading the release notes I couldn’t think there was anything that would have an impact on this.