Repository navigation
Pass group ids directly in the timeSeriesGroupToSamplingKey benchmark - #124809
Merged
alexey-milovidov merged 1 commit intoOct 9, 2026
Merged
alexey-milovidov merged 1 commit into
alexey-milovidov merged 1 commit into
Conversation
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]>
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).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261009-024700 |
This was referenced Oct 9, 2026
Contributor
|
Workflow [PR], commit [247adef] Summary: ✅
AI ReviewSummaryThis PR updates Final Verdict
|
alexey-milovidov
approved these changes
Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #98708
Related: #116376
Changelog category (leave one):
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 #0turnedPerformance 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.arrayElementover a constant array, which copies row by row through a virtualinsertFrom. 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) + 1directly.length(groups)keeps the subquery evaluated: without it the groups are never registered and the function throwsGroup 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), andperf.pyruns the test cleanly. The query goes from 84 to 52 ms, now spent ingetSamplingKeyByGroup,extractGroupFromColumnand 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_tagandpromql_tags_transformuse 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
26.10.1.1972-master(included in26.10and later)