Skip to content

Stabilize the wide-string greatest query of the least_greatest_const_columns performance test - #122784

Merged
egor-click merged 1 commit into
ClickHouse:masterfrom
groeneai:stabilize-least-greatest-const-columns
Sep 29, 2026
Merged

egor-click merged 1 commit into
ClickHouse:masterfrom
groeneai:stabilize-least-greatest-const-columns

Conversation

@groeneai

@groeneai groeneai commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119108

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):

Not required: CI-only change.

Description

least_greatest_const_columns #2 (greatest of toString(number) and four 256-byte constants) was the only failed query of arm 4/6 on #122184: 0.2203 -> 0.2630 s, confirmed_regression. It reads no table, so that PR cannot reach it.

Runs where the two servers differ by more than 15% (14 days to 2026-09-28):

#2 #3
amd, raw samples 94/775 0/775
arm, raw samples 23/1692 0/1692
amd, after the confirm restart 75/1277 0/1350
arm, after the confirm restart 28/4778 0/4826

greatest returns repeat('d', 256) for every row, so chars grows by realloc to 16 MiB per block, and jemalloc moves and copies it whenever it cannot grow it in place. In four CI CPU profiles, samples outside that copy match between the servers within about 3%, while the large_ralloc -> memcpy samples (5/55, 24/118, 26/124, 87/52) are always higher on the slower server. #3 (least) returns the ~7-byte toString(number).

I added a constant 'e' that wins every row, so the result is one byte per row. The query still compares against the four 256-byte constants that #119108 stopped materializing, and still returns a constant argument.

Local check (x86, official master build, pinned like CI amd):

  • CPU samples under large_ralloc: 42.7% before, 0.8% after, all in the toString(number) input that #3 shares.
  • Max/min of 7 runs in one server, p90 over 10 servers: 1.32 before, 1.08 after, 1.10 for #3. Between servers all stayed within 9%: this machine does not reproduce the CI draws.
  • materialize on the constants (the pre-Perf: avoid materializing constant arguments in least and greatest #119108 path) makes the new query 3.96x slower (old: 2.88x).
  • Predicted CI time: 0.119 s amd, 0.144 s arm (README minimum 0.1 s).

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.982-master (included in 26.10 and later)

…columns performance test

`least_greatest_const_columns ClickHouse#2` returns the 256-byte constant `repeat('d', 256)` for every row, so
the result `ColumnString` grows its `chars` by power-of-two `realloc` up to 16 MiB per block. Whether
jemalloc grows that buffer in place or moves and copies it (`large_ralloc` -> `memcpy`) differs
between server processes, and in CI CPU profiles that copy is the only part of the query whose sample
count differs between the two servers. In 14 days the two servers differed by more than 15% in 94 of
775 amd and 23 of 1692 arm runs of this query, and in none for `ClickHouse#3`, which takes the same arguments
with `least` and returns the ~7-byte `toString(number)`.

Add a constant `'e'` that wins every row, so the result is one byte per row. The query still compares
`toString(number)` against the four 256-byte constants that are not materialized since ClickHouse#119108, and
still returns a constant argument.

Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/36432228454/job/109047348805
PR: ClickHouse#122184

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Sep 29, 2026
@groeneai

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

Pre-publication review of this head by an independent model (engine: codex) and my own cold review: 0 findings, nothing to adjudicate.

Session id: cron:clickhouse-review-slot-10:20260928-234300

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c816b4e]

Summary: ✅


AI Review

Summary

This PR changes tests/performance/least_greatest_const_columns.xml so the wide-string greatest benchmark still compares toString(number) against the same 256-byte constant arguments, but now returns a short constant winner instead of a 256-byte result. That removes allocator-dependent ColumnString growth noise without weakening the benchmark's coverage of the constant-argument path introduced in #119108. I did not find a correctness, coverage, or PR-metadata issue in the current diff.

Final Verdict

Status: ✅ Approve

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the mechanism: on an official master build, 42.7% of the old query's CPU samples are in large_ralloc -> memcpy on every run (0.8% for the new query, none of it in greatest). The per-process draw itself does not reproduce on my machine; the four CI profiles tie it to this copy.
b Root cause explained? The 256-byte winner makes chars grow by power-of-two realloc to 16 MiB per block; whether jemalloc grows it in place or moves and copies it differs between server processes, so the two servers differ by a copy that is not the code under test.
c Fix matches root cause? Yes: the result becomes one byte per row, so the large reallocation copies are gone. No threshold, row count, query or index is changed.
d Test intent preserved / new tests added? Yes: still greatest over String with the four 256-byte constants and a constant winner. Materializing the constants (the path before #119108) now costs 3.96x, against 2.88x before. Test-only change.
e Both directions demonstrated? Yes, old vs new query on the same server: 42.7% vs 0.8% of samples in the copy; max/min of 7 runs within one server, p90 over 10 servers: 1.32 vs 1.08 (1.10 for #3).
f Fix is general across code paths? N/A (test-only). The other four queries return UInt64 or a ~7-byte string and are quiet in CI; they are unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only).
h Backward compatible? (maintainer-approved exception only) Yes: test-only, no settings. The query text changes, so its history restarts under the new display name.
i Invariants and contracts preserved? Yes: sum(length(...)) is 5000000 for the new query (1280000000 before); perf.py runs all five queries on two servers with no errors.

Session id: cron:clickhouse-impl-slot-6:20260928-231200

@egor-click
egor-click added this pull request to the merge queue Sep 29, 2026
Merged via the queue into ClickHouse:master with commit d3e4251 Sep 29, 2026
149 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 29, 2026
@clickhouse-gh clickhouse-gh Bot added comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants