Repository navigation
Do not rewrite unchanged generated files on a CMake re-run, and configure faster - #130176
Conversation
…-run Several configure-time generators rewrote their output on every CMake run even when the content did not change, so after any re-run ninja recompiled their dependents and relinked: - contrib/cctz-cmake: file(REMOVE) + file(APPEND) of TimeZones.generated.cpp (1 TU). - contrib/llvm-project-cmake: file(WRITE) of the six llvm/Config/*.def files and llvm/Support/VCSRevision.h (18 TUs, including src/Interpreters/JIT/CHJIT.cpp). - src/Storages/System: file(RENAME) of StorageSystemLicenses.generated.cpp (1 TU, a 13 MB source). - contrib/musl-cmake: bits/alltypes.h, bits/syscall.h and version.h. bits/alltypes.h is on the -isystem path of every C/C++/ASM compile of a musl build, so a re-run dirtied almost the whole build (1682 compile edges for the _lz4 target alone). Add write_file_if_changed() to cmake/utils.cmake. It writes a temporary file and copies it with file(COPY_FILE ... ONLY_IF_DIFFERENT), so an unchanged file keeps its timestamp. A file(READ) + STREQUAL comparison is not used: file(READ) drops '\r', so content with a carriage return would never compare equal. The licenses source already goes through a .tmp file and is copied the same way; the copy still happens only after the script succeeded. The time zone files stay dependencies of TimeZones.generated.cpp.o through the #embed entries of its depfile, so a tzdata change still rebuilds it. Measured on a debug build (touch CMakeLists.txt, then ninja clickhouse): the 20 compile edges are gone (58 -> 29 ninja edges); every generated file is byte-identical to before. Based on part (d) of patch 2 by snelheidai in ClickHouse#130064. Co-Authored-By: Claude Opus 5.5 <[email protected]>
list-licenses.sh runs at configure time. It forked dirname, basename, rev, cut and grep for each vendored Rust crate (about 1400) and walked the whole tree of every C/C++ library. - process_rust_crate uses shell builtins only, and xargs runs it on batches of 64 crates. - process_library looks at the top-level license candidates first and walks the whole tree only when none of them is chosen. This is equivalent with any awk: after LC_ALL=C sort every depth-1 line comes first, and once a line matches, only lines with depth <= min_depth can change the result. Keeping only the depth-1 candidates whenever there is one is NOT equivalent under mawk (the awk of the CI builder image), where IGNORECASE has no effect: it drops libxml2, rapidjson and sz3 from system.licenses. - StorageSystemLicenses.sh reads the license files with $(< file) instead of $(cat file). The output is byte-identical to before under both gawk and mawk, and a crate with an unrecognized license still makes the script fail. list-licenses.sh: 2.0 s -> 0.5 s; StorageSystemLicenses.sh: 5.1-5.5 s -> 0.8 s. Based on part (d) of patch 2 by snelheidai in ClickHouse#130064. Co-Authored-By: Claude Opus 5.5 <[email protected]>
cmake/git.cmake runs git status only to print the state of the tree into the configure log. A plain git status scans the work trees of all submodules (5.0-5.6 s here); with --ignore-submodules=dirty it takes 0.2 s. A submodule checked out at another commit is still listed; modified or untracked content inside a submodule is no longer listed. Nothing reads this output (no OUTPUT_VARIABLE), and system.build_options does not contain it. Based on part (d) of patch 2 by snelheidai in ClickHouse#130064. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261108-161900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261108-141300 |
|
cc @Algunenano @thevar1able, could you review this and add the |
|
Workflow [PR], commit [f085015] Summary: ✅
AI ReviewSummaryPR #130176, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No inline findings. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
CI finish ledger - f085015Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261108-203007 |
|
About the |
This is not the established procedure. At the very least you need to propose a possible fix to address this problem. @groeneai |
|
Acknowledged, closing that row without a fix was wrong. I am working on a fix for this hung check and will link the PR here (and on #125015, which has the same row). |
|
@groeneai the hang is a regression from #129257 (merged Nov 6), and a small patch fixes it (below). #129257 moved aggregate window evaluation into per-block batches. CI shows the same. In the 90 days before Nov 3, no hung check involved a window query. On Nov 3, master hung on a fuzzed The patch gives On master 7a516a1 (x86, Release build), with both CI hung queries verbatim:
The 248 window-related stateless cc @Michicosun as the author of #129257. Patch against master 7a516a1 (these files are unchanged on current master)--- a/src/Processors/Transforms/WindowTransform.cpp
+++ b/src/Processors/Transforms/WindowTransform.cpp
@@ -86,6 +86,8 @@
, arguments(params.input_header, functions)
, frame(params)
{
+ bounds.is_cancelled = &getCancellationFlag();
+
for (const auto & function : functions)
if (const auto general = asGeneralWindowFunction(function.aggregate_function))
general->checkWindowFrameType(params.window_description);
@@ -133,7 +135,7 @@
void WindowTransform::computeReadyRows()
{
- /// Cancellation is checked per row here; window functions evaluate each batch without cancellation checks
+ /// Cancellation is checked per row here; inside a batch, only functions whose cost per row grows with the frame check it
while (!isCancelled())
{
if (bounds.rows != 0 && peers.current().location.block != batch_start.block)
@@ -201,6 +203,14 @@
for (auto & slot : aggregate_functions)
first_row = std::min(first_row, slot.function->evaluate(bounds, arguments.view(slot.function_index), *current_results[slot.function_index]));
+ /// A function may stop early on cancellation and leave its result column short, so the batch is not packed.
+ if (isCancelled())
+ {
+ current_results.clear();
+ clearBounds(bounds);
+ return;
+ }
+
const bool block_complete = batch_start.row + bounds.rows == block.rows_count;
if (block_complete)
packReadyBlock();
--- a/src/WindowFunctions/Aggregate/AggregateWindowFunctionRecalculate.cpp
+++ b/src/WindowFunctions/Aggregate/AggregateWindowFunctionRecalculate.cpp
@@ -36,6 +36,10 @@
{
for (Int64 from = 0; from < bounds.rows;)
{
+ /// A moved frame start re-aggregates the whole frame, so one batch can cost rows * frame additions.
+ if (bounds.isCancelled())
+ break;
+
const Int64 to = equalFrameRun(bounds, from);
const Int64 frame_start = bounds.frame_start[from];
const Int64 frame_end = bounds.frame_end[from];
--- a/src/WindowFunctions/Common/WindowBounds.h
+++ b/src/WindowFunctions/Common/WindowBounds.h
@@ -3,6 +3,8 @@
#include <Common/PODArray.h>
#include <base/types.h>
+#include <atomic>
+
namespace DB
{
@@ -16,6 +18,12 @@
PaddedPODArray<Int64> peers_end;
PaddedPODArray<Int64> peer_group_index;
PaddedPODArray<Int64> partition_end;
+
+ /// Cancellation flag of the processor evaluating the batch. A function whose cost per row grows with the frame
+ /// checks it inside the batch and may stop early; the transform then discards the incomplete batch.
+ const std::atomic<bool> * is_cancelled = nullptr;
+
+ bool isCancelled() const { return is_cancelled && is_cancelled->load(std::memory_order_relaxed); }
};
void clearBounds(WindowBounds & bounds);
--- a/src/WindowFunctions/General/WindowFunctionExponentialTimeDecayed.cpp
+++ b/src/WindowFunctions/General/WindowFunctionExponentialTimeDecayed.cpp
@@ -158,6 +158,10 @@
auto & data = assert_cast<ColumnFloat64 &>(result).getData();
for (Int64 i = 0; i < bounds.rows; ++i)
{
+ /// Every row scans its whole frame.
+ if (bounds.isCancelled())
+ break;
+
const Int64 start = bounds.frame_start[i];
const Int64 end = bounds.frame_end[i];
Float64 max = std::numeric_limits<Float64>::quiet_NaN(); |
|
@groeneai Please remember it's ok/expected to investigate what caused a new issue and propose a revert so we stop having issues in CI |
|
Understood, I will do that from now on. This hung check points to #129257 (merged on Nov 6). I am verifying that the query stops on |
|
Reverting #129257 makes the aggregate hangs cancellable again, but not the Nov 3 hang on master. At the first parent of #129257 (e1e15a9), aggregates are still re-aggregated row by row inside the The 8th is a fuzzed |
|
I opened the revert of #129257: #130331. With |
|
Fixing PR for the #130328 does not cover the 2026-11-03 master hang in |
f51f86e
Related: #130064
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A CMake re-run no longer rewrites unchanged generated files (
TimeZones.generated.cpp,StorageSystemLicenses.generated.cpp, the LLVM.defheaders and the muslbits/*.hheaders), so it no longer recompiles the code that uses them, and it configures faster:git statusskips the work trees of submodules andlist-licenses.shno longer forks per vendored Rust crate.Description
Based on part (d) of patch 2 by snelheidai in #130064.
Every CMake re-run rewrote some configure-time outputs even when their content did not change, so ninja recompiled their dependents: 20 TUs in a debug build (
TimeZones.generated.cpp, the 13 MB licenses source, 18 LLVM/CHJIT.cppTUs), and almost everything in a musl build, becausebits/alltypes.his on every compile's-isystempath. The newwrite_file_if_changed()incmake/utils.cmakewrites a temporary file and copies it withfile(COPY_FILE ... ONLY_IF_DIFFERENT); the licenses source is copied the same way. Configure time also went to agit statusthat scans all submodule work trees (now--ignore-submodules=dirty; the configure log no longer lists modified content inside submodules) and to a license script that forked about 10 processes per crate.Two changes against the posted patch: its
process_libraryshortcut dropslibxml2,rapidjsonandsz3fromsystem.licensesunder mawk, the awk of the CI builder image, so the shortcut here is equivalent under any awk; and the helper does not usefile(READ), which drops the\rof a CRLF line end.Validation, debug build, ccache,
touch CMakeLists.txt, median of 4 runs:ninja build.ninjaninja clickhouseninja _lz4The generated files,
system.licensesand thelist-licenses.shoutput (gawk and mawk) are byte-identical to master. Theninja clickhousegain is smaller than the saved compiles because master re-runs the Rust archive post-processing on every build (part (a) of #130064).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130176]
Version info
26.11.1.1783-master(included in26.11and later)