Skip to content

cmake: kconfig: stop rehashing every Kconfig source on re-configure - #117017

Open
kartben wants to merge 2 commits into
zephyrproject-rtos:mainfrom
kartben:cmake-kconfig-checksum
Open

cmake: kconfig: stop rehashing every Kconfig source on re-configure#117017
kartben wants to merge 2 commits into
zephyrproject-rtos:mainfrom
kartben:cmake-kconfig-checksum

Conversation

@kartben

@kartben kartben commented Aug 21, 2026

Copy link
Copy Markdown
Member

Two independent cleanups to the Kconfig checksum handling, split into a commit each.

Quadratic accumulation. The checksums are built with set(var "${var}${checksum}") in loops that run once per parsed Kconfig file — 5001 of them for a hello_world build. CMake strings are immutable, so every iteration copies the whole accumulator. string(APPEND) avoids that, and the configure dependencies are registered in one set_property() call rather than one per file.

Dead work. The loop that recalculates the checksum after kconfig.py runs is only consumed inside if(CREATE_NEW_DOTCONFIG). On any configure that does not regenerate .config, its result is discarded — 5001 file hashes for nothing. It moves into the block that consumes it.

Measured in isolation over the 5001 sources of a hello_world build:

before after
recalculation loop, on a re-configure 168 ms skipped entirely
remaining checksum loop 168 ms 123 ms
configure-dependency registration 8 ms 2 ms

The resulting checksum is byte-identical — .cmake.dotconfig.checksum hashes the same at both commits and on main so cached builds are unaffected.

The checksums are accumulated with set(var "${var}${checksum}") in loops
that run once per parsed Kconfig file, 5001 of them for a hello_world
build. CMake strings are immutable, so every iteration copies the whole
accumulator and the loops are quadratic.

Accumulate with string(APPEND) instead, and register the configure
dependencies in a single set_property() call rather than one per file.
Measured in isolation over 5001 sources, a checksum loop goes from
168 ms to 123 ms and the dependency registration from 8 ms to 2 ms. The
resulting checksum is byte-identical.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
…used

The loop that recalculates the checksum after kconfig.py runs is only
consumed inside if(CREATE_NEW_DOTCONFIG). On any configure that does not
regenerate .config its result is discarded, so hashing all 5001 parsed
Kconfig sources is pure waste, measured in isolation at 168 ms.

Move the loop into the block that consumes it. The file(STRINGS) read
above stays where it is, as it also feeds the CMAKE_CONFIGURE_DEPENDS
registration, which must keep running unconditionally.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
@kartben
kartben force-pushed the cmake-kconfig-checksum branch from 5633193 to 0b722b4 Compare August 21, 2026 08:30
@kartben
kartben marked this pull request as ready for review August 21, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants