Skip to content

Split the timeSeries*ToGrid registrations into per-family translation units - #120316

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/split-timeseries-registration-translation-units
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/split-timeseries-registration-translation-units

Conversation

@groeneai

@groeneai groeneai commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #112842

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Registration of the timeSeries*ToGrid aggregate functions is split across one translation unit per traits header, so no single object file exceeds the 50 MB limit checked at link time. No user-visible change.

Description

Build (amd_release) and Build (arm_release) fail on master at the programs/clickhouse link, on
utils/check-large-objects.sh:

  56842736 .../TimeSeries/AggregateFunctionTimeseriesHelpers.cpp.o
^ It's not allowed to have so large translation units.

Red on both arches at 3a43db4d688f and again at c2b4e8be753d three hours later, each time dropping 26
downstream jobs: every Stateless tests (*_release) shard, both ClickBench, all 12
Performance Comparison (*, master_head), and the Post Hooks upload of the master-head perf baseline
binary. Offered on #112842; opened because the builds are still red with no revert or fix in flight.

Root cause. registerAggregateFunctionTimeseries() registered all 20 timeSeries*ToGrid functions in
one translation unit, each instantiating AggregateFunctionTimeseries<Traits, ...> for 2 value types x 2
timestamp types: 80 instantiations of the shared base header. Only the ThinLTO flavours reach the limit,
since there the .o is LLVM bitcode carrying full IR; every non-LTO flavour built the same commit fine.

Change. One registration function per traits header, each in its own .cpp, the shared dispatch
machinery in a new AggregateFunctionTimeseriesHelpers.h, and registerAggregateFunctionTimeseries()
reduced to 11 calls. Pure code motion: the 20 registration blocks move byte-for-byte;
registerAggregateFunctions.cpp, utils/check-large-objects.sh and CMake are untouched (the directory is
globbed). The in-flight PromQL PRs touching this file will need a rebase. Listing the unit in
TU_EXCLUDES would also clear the red but retires the gate for it; happy to switch if you prefer.

Validation. With the release flags the object measures 56,842,832 B locally against CI's
56,842,736 B and the check exits 1; after the split the largest is 11,249,200 B and it exits 0.
SELECT * FROM system.functions WHERE name ILIKE 'timeSeries%' is byte-identical before and after (48
rows, same md5), including the timeSeriesLastToGrid alias row; verified able to fail by dropping a
registration. All 22 existing timeSeries stateless tests pass, identically to the base binary.

Per-object sizes under clickhouse_aggregate_functions.dir/TimeSeries/, ThinLTO (click to expand)
before                                          after
56,842,832  AggregateFunctionTimeseriesHelpers      11,249,200  ...LinearRegression
 4,124,300  AggregateFunctionLast2Samples            9,954,696  ...ExtrapolatedValue
 3,295,484  AggregateFunctionTimeSeriesTopKMasks     7,721,680  ...CompensatedSum
 2,309,992  AggregateFunctionTimeSeriesGroupArray    7,609,316  ...Min
   659,376  AggregateFunctionTimeseriesQuantileToGrid 7,207,864  ...Changes
                                                     7,195,620  ...Max
                                                     5,697,780  ...QuantileToGrid
                                                     4,807,632  ...InstantValue
                                                     4,781,148  ...Count
                                                     4,124,300  AggregateFunctionLast2Samples
                                                     3,944,528  ...PresentToGrid
                                                     3,502,060  ...ToGridSparse
                                                     3,295,484  ...TimeSeriesTopKMasks
                                                     2,309,992  ...TimeSeriesGroupArray
                                                       442,588  ...Helpers

The gate measures the per-object maximum, which falls from 56.8 MB to 11.2 MB. Total bytes in the
directory rise from 67.2 MB to 83.8 MB, since 10 more units each re-emit parts of the shared base header.


Workflow [PR]
Sync PR [sync-upstream/pr/120316]

… units

registerAggregateFunctionTimeseries() registered all 20 timeSeries*ToGrid
aggregate functions in a single translation unit. Each registration passes its
own generic lambda to createAggregateFunctionTimeseries, which dispatches over
2 value types (Float64, Float32) and 2 timestamp/interval pairs (DateTime64,Int64
and UInt32,Int32), so the unit carried 20 x 4 = 80 full instantiations of the
1305-line AggregateFunctionTimeseriesBase.h.

Under ThinLTO the object file is LLVM bitcode carrying full IR, several times
larger than a native object, and the unit reached 56,842,736 B against the
50,000,000 B ceiling that utils/check-large-objects.sh enforces as a post-link
command on the programs/clickhouse edge. Build (amd_release) and Build
(arm_release) are the only MasterCI builds configured with -DENABLE_THINLTO=1,
which is why they were the only flavours to fail; amd_binary, the debug builds,
the sanitizer builds and arm_tidy all carry -DENABLE_THINLTO=0 and built the
same commit fine.

Each traits header now owns a registration function in its own .cpp, the shared
dispatch machinery moves to AggregateFunctionTimeseriesHelpers.h, and
registerAggregateFunctionTimeseries() becomes 11 calls. The 20 registration
blocks are moved byte-for-byte. registerAggregateFunctions.cpp keeps its single
entry point and is untouched, TU_EXCLUDES gains nothing, the 50 MB limit is
unchanged, and no CMake change is needed because the directory is globbed.

The Setting:: externs stay in a .cpp behind
assertTimeSeriesAggregateFunctionsEnabled(), so the header pulls in no settings
machinery for the 12 units that include it. The nested TimeSeriesToGrid
namespace is required rather than cosmetic: createWithValueType and
createWithTimestampAndValueTypes also name unrelated anonymous-namespace helpers
in AggregateFunctionTimeSeriesGroupArray.cpp and AggregateFunctionLast2Samples.cpp.
factory.registerAlias("timeSeriesLastToGrid", ...) was the one statement in the
old body outside the 20 documentation blocks; it moves with its target and stays
after it, because registerAlias resolves the target at call time.

Measured with the release build's flags: the object matches CI to within 96 B
(56,842,832 B locally), check-large-objects.sh exits 1 before and 0 after, and
the largest object in that directory falls to 11,249,200 B. Per-object bytes are
what the gate measures; total bytes in the directory rise from 67.2 MB to
83.8 MB, since 10 more units each re-emit parts of the shared base header.
SELECT * FROM system.functions WHERE name ILIKE 'timeSeries%' is byte-identical
before and after over all 16 columns (48 rows, same md5), including the
timeSeriesLastToGrid alias row; that comparison was verified able to fail by
dropping one registration and observing the missing row. All 22 existing
timeSeries stateless tests pass, with verdicts identical to the pristine binary.

Related: ClickHouse#112842

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold read of the
resulting tree. Nothing blocking; the three nits below are mine, disclosed rather than fixed, and I am
happy to push any of them on request.

# Sev Finding Verdict Evidence / action
1 💡 AggregateFunctionTimeseriesHelpers.h:26 says the nested TimeSeriesToGrid namespace is "required" AGREE, not fixed Overstated. Both same-named helpers it cites have internal linkage (AggregateFunctionTimeSeriesGroupArray.cpp:27,46 and AggregateFunctionLast2Samples.cpp:27 are inside namespace { }) and neither file includes the new header, so dropping the nesting would still compile. The nesting is defensive, not mandatory. Say the word and I will delete those two lines; the commit message keeps the rationale.
2 💡 Same header, :175-177: the declaration block's comment repeats the instantiation arithmetic and the size gate AGREE, not fixed That belongs in the commit message, which already has it. Only the invariant, one registration unit per traits header, needs to be visible at that spot. Can condense to one line.
3 💡 Why no CMake change for 10 new source files AGREE, informational add_headers_and_sources(clickhouse_aggregate_functions TimeSeries) globs the directory. Note in passing that src/AggregateFunctions/TimeSeries/CMakeLists.txt is dead (nothing calls add_subdirectory for that path; the only one is src/Functions/CMakeLists.txt:176, for a different directory), so it does not double-compile them. Pre-existing, left alone.

What I verified independently of the author, since this is pure code motion and the risk is a lost
registration rather than a logic bug: all 20 documentation-plus-registration blocks are present exactly
once and byte-identical on non-blank lines (1705 lines in, 1705 out, empty symmetric difference), 9 of the
11 files being contiguous in-order runs of the original body and Max/Min two runs each because the
original interleaved them; the single registerAlias in the directory still sits immediately after its
target, which matters because IFactoryWithAliases::registerAlias throws when the real name is not yet
registered; the shared machinery moved byte-identically apart from the namespace rename, the forward
declarations, and the private-preview settings check being extracted verbatim and still evaluated first,
so error precedence is unchanged; the dispatcher is exactly 11 calls and nothing else; and per-file
ErrorCodes declarations match uses in all 13 files, which is what the style check keys on.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-9:20260916-040100

@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [60c63c1]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, 7/8) ERROR
Fast test (arm_darwin) DROPPED
Build (amd_darwin) DROPPED
Build (arm_darwin) DROPPED
Build (arm_v80compat) DROPPED
Build (amd_freebsd) DROPPED
Build (ppc64le) DROPPED
Build (amd_compat) DROPPED
Build (amd_musl) DROPPED
Build (riscv64) DROPPED

AI Review

Summary

This PR splits the timeSeries*ToGrid registration monolith into per-family translation units so ThinLTO no longer produces a single oversized object file. I did not find correctness, compatibility, or coverage issues in the current head: the moved registration bodies still cover the same 20 functions and alias, the shared helper extraction preserves the existing argument-validation and preview-gate behavior, and the PR CI is green including Build (amd_release) and Build (arm_release).

Final Verdict

✅ No findings. The current patch looks like behavior-preserving code motion that fixes the intended release-build object-size failure.

@groeneai groeneai changed the title Related: https://github.com/ClickHouse/ClickHouse/pull/112842 Split the timeSeries*ToGrid registrations into per-family translation units Sep 16, 2026
@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 16, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Sep 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 60c63c1f4 with master 61124de86 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes, compile time of recompiled translation units.

Binary sizes

No master baseline size data yet for programs/clickhouse-stripped.

Object file sizes ⚠️

4 object files changed (+1.90 MiB total), 10 added.

Object file Master PR Δ
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… 10.11 MiB 69.06 KiB -10.04 MiB (-99.33%)
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 1.92 MiB +1.92 MiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 1.69 MiB +1.69 MiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 1.23 MiB +1.23 MiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 1.21 MiB +1.21 MiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 1.15 MiB +1.15 MiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 1.13 MiB +1.13 MiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 1.01 MiB +1.01 MiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… 75.46 KiB 817.02 KiB +741.55 KiB (+982.64%)
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 699.20 KiB +699.20 KiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 623.58 KiB +623.58 KiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/TimeSeries/AggregateFunctionTi… new 604.08 KiB +604.08 KiB

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units ⚠️

18 translation units recompiled, 82 s compile time in total, 8 of them have a recent master baseline.

Translation unit Master PR Δ vs median
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesHelpers.cpp 39.7 s 2.2 s -37.5 s (-94%)

Translation units without a recent master baseline:

  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesLinearRegression.cpp: 9.5 s
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesExtrapolatedValue.cpp: 9.2 s
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesCompensatedSum.cpp: 7.7 s
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesMin.cpp: 7.5 s
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesChanges.cpp: 7.5 s
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesMax.cpp: 7.2 s
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesCount.cpp: 5.7 s
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesInstantValue.cpp: 5.6 s
Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse DB::registerAggregateFunctionTimeseries(DB::AggregateFunctionFactory&) 167.92 KiB removed -167.92 KiB (-100.00%)

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 60c63c1

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan_ubsan, db disk, 7/8) job-level Failed to pre-pull Docker images needed by the test batch, 0 test rows in the CI database, so the shard died before any test started. minio/mc and minio/minio were removed from Docker Hub, so the compose pins no longer resolve and the batch pre-pull is denied. Not reachable from this diff, which touches 13 files under src/AggregateFunctions/TimeSeries and no integration test, compose file or image pin. Measured over the last 12 hours: 41 rows on this shard over 35 distinct pull requests, and 92 rows over 52 heads and 46 pull requests across the four shards that carry the affected images, including 22 rows on master and release branches. So it is not specific to this branch #119999 (mine, open)
Sync - CH Inc sync (private, not actionable by me)

Mergeable Check and PR are the two praktika aggregators of the row above, not independent
failures. The other 171 check-runs at this head are green or skipped: the paginated check-run census
(172 raw, 172 after dedupping by name to the newest started_at) reports exactly the one failure
above and zero runs still queued or in progress, and Build (amd_release), Build (arm_release),
Finish Workflow, Style check and Fast test are all green. The two release builds passing is the
point of this change: they are the checks that reject the oversized translation unit on master.

Session id: cron:our-pr-ci-monitor:20260916-070103

@nikitamikhaylov

Copy link
Copy Markdown
Member

@groeneai merge master.

…series-registration-translation-units

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged master at 61124de86664 into the branch; new head is 6fc219622eac. The merge is clean: master has not touched src/AggregateFunctions or utils/check-large-objects.sh since my base, so the split content is byte-identical to the head CI already built green, and check-large-objects.sh still exits 0 on a local ThinLTO build of the merged tree. CI is running on the new head.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Correction to the comment above: your revert #120336 merged at 09:00:23Z, one minute after I pushed, so the head here carries pre-revert master 61124de8. The branch therefore conflicts with master in AggregateFunctionTimeseriesHelpers.cpp, and no CI has started on the new head, because praktika builds the merge commit.

The revert restores src/AggregateFunctions/TimeSeries byte-identically to its pre-#112842 state, so master builds again. I measured that content in the same release ThinLTO configuration my earlier number came from (it matched CI to within 96 B): AggregateFunctionTimeseriesHelpers.cpp.o is 46,551,804 B, or 93.1% of the 50,000,000 B limit. The four reverted functions accounted for 10,291,028 B of the 56,842,832 B object, about 2.6 MB each, so the 3,448,196 B of headroom left on master is less than two more such registrations and the re-land trips the same gate.

That makes this PR preparation for the re-land rather than a master fix. Your call: I re-do the split against post-revert master (16 registrations instead of 20), or I close this PR and the split rides with the re-land. I will not touch the PR until you say which.

@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: f810ad12-ecbd-45b6-88e5-0604f77af5d0
  • MIRAI run: 0a111f26-3c49-4526-a893-30fb2a37d504
  • PR check IDs:
    • clickbench_418639_1789561193
    • clickbench_418645_1789561193
    • clickbench_418651_1789561193
    • tpch_adapted_1_official_418662_1789561193
    • tpch_adapted_1_official_418673_1789561193
    • tpch_adapted_1_official_418711_1789561193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants