Skip to content

Pass group ids directly in the timeSeriesGroupToSamplingKey benchmark - #124809

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-timeseries-sampling-key-direct-group-ids
Oct 9, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-timeseries-sampling-key-direct-group-ids

Conversation

@groeneai

@groeneai groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #98708
Related: #116376

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

timeseries_group_to_sampling_key #0 turned Performance Comparison (arm_release, master_head, 4/6) red on #98708 (report, +26.8%) and, 6 minutes later against the same master reference, on #116376 (+23.8%). Neither PR touches this code. In 30 days, 13 arm runs moved more than 15% one way, on either side.

About half of the query's CPU went to groups[number % 4096 + 1], i.e. arrayElement over a constant array, which copies row by row through a virtual insertFrom. In the job profiles of all 5 slow runs I could get, only that frame grew in every run (x1.4 to x2.2); the other frames moved by at most ~20 samples, in both directions. The slow state also survived the server restarts of the confirmation step.

The tags collector numbers groups 0, 1, 2, ... with 0 for the empty tag set, so the 4096 groups built by the subquery are 1..4096 and the query can pass number % length(groups) + 1 directly. length(groups) keeps the subquery evaluated: without it the groups are never registered and the function throws Group 1 is out of bounds.

Validation on x86 with an official master build: over the 20M rows both expressions return the same keys (sum, groupBitXor, 0 rows differ), and perf.py runs the test cleanly. The query goes from 84 to 52 ms, now spent in getSamplingKeyByGroup, extractGroupFromColumn and the id arithmetic. Across 24 processes per query, the medians span 79-91 ms before and 52-53 ms after. I cannot measure arm locally; the arm results after merge will show whether it is stable there. timeseries_extract_tag and promql_tags_transform use the same lookup but are stable on arm, so I left them as they are.

🤖 Generated with Claude Code


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

Version info

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

The benchmark looked each row's group up in a constant array,
`groups[number % 4096 + 1]`. About half of its CPU went to that lookup
(`arrayElement` over a constant array copies row by row through a virtual
`insertFrom`), not to the sampling-key code the test measures. On arm some
builds run that loop about twice as slow in every server process: in the
job profiles of the slow runs on ClickHouse#98708, ClickHouse#116376, ClickHouse#117754, ClickHouse#123545 and
ClickHouse#123188 only that frame grew (x1.4 to x2.2) while every other frame stayed
flat, so the query moved 20-27% and the confirmation restart reproduced it.

The per-query tags collector numbers groups 0, 1, 2, ... with 0 reserved for
the empty tag set (`ContextTimeSeriesTagsCollector.h`), so the 4096 groups
the subquery creates are 1..4096 and the query can pass
`number % length(groups) + 1` directly. `length(groups)` keeps the scalar
subquery referenced: without it the analyzer drops the subquery, no group is
registered and the function throws `Group 1 is out of bounds`.

Checked on x86 with an official master build: the same keys over the 20M
rows (`sum` and `groupBitXor` equal, 0 rows differ), 84 -> 52 ms, and the
per-process medians of 24 processes span 79-91 ms before and 52-53 ms after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026

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 review of the diff (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 toUInt64 is redundant: number % length(groups) + 1 is already UInt64 DISAGREE The function accepts only UInt64; with a literal divisor the same expression is UInt32 (modulo(number, 4096_UInt16)). A same-type cast returns the input column, so it costs nothing. Kept.
2 💡 The commit message says every other profile frame stayed flat; getSamplingKeyByGroup moved by up to ~20 samples in both directions AGREE, noted The PR description states it precisely. Not blocking.

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

Session id: cron:clickhouse-review-slot-9:20261009-024700

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [247adef]

Summary: ✅


AI Review

Summary

This PR updates tests/performance/timeseries_group_to_sampling_key.xml so the benchmark feeds timeSeriesGroupToSamplingKey directly with the dense UInt64 group ids produced by timeSeriesTagsToGroup, instead of paying the per-row arrayElement cost from indexing a constant array first. I did not find a correctness or contract issue in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 9, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 9, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 9, 2026
Merged via the queue into ClickHouse:master with commit 7682f17 Oct 9, 2026
163 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 9, 2026
@clickhouse-gh clickhouse-gh Bot added comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... 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-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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