Skip to content

Use larger groups in the aggregation_in_order_if_null_map performance test - #133621

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-aggregation-in-order-if-null-map-large-groups
Nov 23, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-aggregation-in-order-if-null-map-large-groups

Conversation

@groeneai

@groeneai groeneai commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #120906 (comment)
Related: #100759
Related: #118025
Related: #127697

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

The aggregation_in_order_if_null_map performance test aggregates groups of 1024 rows (128 for corr and argMinIf, 256 for minIf) instead of 8, so its timings depend much less on the code layout of a build.

Description

Performance Comparison (amd_release, master_head, 1/8) failed on #120906 with aggregation_in_order_if_null_map #3 sumIf(y, cn) +35% (#0 +27%), and the test goes red on unrelated PRs with a different query each time. Of 2667 amd builds since 2026-10-26, 73 (2.7%) run one of its queries 16-35% slower than the rest of the same build; a re-run reproduces it.

With groups of 8 rows, about 75% of each query is per-group work: finding the group end, the -If/-Null adapters, creating and finalizing the state. Its speed depends on how a build places these small hot functions: the #120906 build has the same instruction count and one more branch miss per group.

The six queries are disabled (their history keys stay) and appended on three new tables: three on groups of 1024 rows, corr and argMinIf (the least layout-sensitive) on groups of 128 and minIf on groups of 256, where smaller groups keep their guards. One part per table, 0.18-0.23 s per query.

Validation, ratios slow build / reference build in the same server processes: the #120906 build runs the old #0 / #3 at 1.31x / 1.39x and the new copies at 1.016x / 1.020x (sumIf 1.067x in another run); on 7 slow CI builds the new queries stay within 6.7% (A/A 2.5%), below the 15% minimum change threshold. The test still guards #118025: restoring the value-initialised row_end-sized flag buffer at each site master still reaches (AggregateFunctionSum.h, AggregateFunctionAvg.h, SingleValueData.cpp, AggregateFunctionNull.h) slows at least one of its queries by 1.2x-1.8x (mutant / master build, same results, A/A within 3%). Reverting the per-group buffer #122505 removed from the -If adapters slows argMinIf by 1.21x and minIf by 1.28x; sumIf, the only other query on these adapters, moves 1.13x on its 1024-row groups.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.12.1.222-master (included in 26.12 and later)

…ce test

With groups of 8 rows about 75% of each query is per-group work (the
group-end search of in-order aggregation, the `-If`/`-Null` adapters,
state create and finalize). Its speed depends on how a build lays out
these small hot functions: 73 of 2667 amd builds since 2026-10-26 run
one of the six queries 16-35% slower than the rest of the same build,
with the same instruction count and one more branch miss per group. That
made the test fail on unrelated PRs (ClickHouse#120906: ClickHouse#3 +35%, #0 +27%) with a
different query each time.

Disable the six queries (their history keys stay) and append them on
three new tables: `sumIfOrDefault`, `avgIfOrDefault` and `sumIf` on
groups of 1024 rows, `corr` and `argMinIf` on groups of 128 rows and
`minIf` on groups of 256 rows. `corr` has the smallest per-group penalty
and needs the smaller groups to keep its ClickHouse#118025 guard (~1.10 at 1024
rows). `argMinIf` and `minIf` keep a guard of ClickHouse#122505: reverting its
change to the variadic and unary `-If` null adapters slows them 1.21x and
1.28x, while the other `-If` queries move +0.9% to +13.2%.

Measured locally with perf.py against the CI reference build: the
ClickHouse#120906 build runs the old #0/ClickHouse#3 at 1.31x/1.39x and the new copies at
1.016x/1.020x in the same processes (`sumIf` 1.067x in another run);
7 slow CI builds stay within 6.7% on the new queries (A/A 2.5%), below
the 15% minimum change threshold. Restoring the value-initialised
`row_end`-sized buffer at each ClickHouse#118025 site master still reaches
(`AggregateFunctionSum.h:669`, `AggregateFunctionAvg.h:539`,
`SingleValueData.cpp:39`, `AggregateFunctionNull.h:769`) slows its
queries 1.2x-1.8x, with identical results.

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

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

Five review rounds (own review + Gate B), last Gate B on this exact tree: 0 findings.

Finding Verdict
❌ Larger groups also dilute fixed per-group costs, so a revert of the -If adapter fast paths of #122505 would no longer cross the 15% floor AGREE: measured with the reverse of #122505's own hunks; argMinIf moved to the 128-row table (1.21x, variadic adapter)
❌ The unary -If null adapter (reached only by minIf) is still below the floor (1.10x on 1024-row groups) AGREE: minIf moved to a 256-row table (1.28x), noise within 1.6% on 7 slow builds
⚠️ Mutant and layout claims need measurements DISAGREE: measured, 21 runs: mutant / master 1.2x-1.8x per site; old vs new shape on the #120906 build 1.31x/1.39x vs 1.016x/1.020x
⚠️ Some quoted numbers came from a disturbed run (corr guard 1.20x, not 1.31x; sumIf 1.067x on the #120906 build in another run) AGREE: description and commit message corrected
💡 SQL names in the test comment should be in backticks (in-tree CLAUDE.md) AGREE: fixed

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano, could you review this? It moves the aggregation_in_order_if_null_map perf test (red on #120906 and on unrelated PRs) from 8-row groups to groups of 1024, 256 and 128 rows, so per-group adapter work no longer dominates and the timings stop depending on the build's code layout, while every #118025 and #122505 buffer site it guards still slows one of its queries by at least 1.2x.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The #120906 CI build (0452ad4) next to the CI reference build, 21 runs: master's #0 / #3 at 1.311x / 1.393x (CI: +27% / +35%).
b Root cause explained? Yes. At 8-row groups ~75% of each query is per-group work (group-end search, -If/-Null adapters, state create/finalize) whose speed depends on the build's code layout: same instructions, +1 branch miss per group.
c Fix matches root cause? Yes. Groups of 1024 rows (128 for corr and argMinIf, 256 for minIf) make the per-group work a small share. No threshold widened.
d Test intent preserved / new tests added? Yes. Restoring the #118025 defect at each of the four sites master still reaches slows its queries 1.2x-1.8x (bar 1.15); reverting #122505's -If adapter change slows argMinIf 1.21x and minIf 1.28x; results identical.
e Both directions demonstrated? Yes. Same processes: old shape +31% / +39%, new shape +1.6% / +2.0% on the #120906 build (sumIf +6.7% in another run); 7 slow CI builds within 6.7%, A/A 2.5%.
f Fix is general across code paths? Yes. All six queries are reshaped (CI flagged #0 #1 #3 #4 #5); each live carrier (Sum, Avg, SingleValueData, AggregateFunctionNull) is guarded separately, the -If null adapters through argMinIf (variadic) and minIf (unary).
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Same aggregate functions, Nullable value / condition / two Nullable arguments, same expressions; exact group sizes; one XML for both architectures.
h Backward compatible? (maintainer-approved exception only) Yes. Test-only. Disabled queries keep indices 0-5, new ones are 6-11. No settings.
i Invariants and contracts preserved? Yes. One part per table, groups of exactly 1024 / 128 / 256 rows, optimize_aggregation_in_order = 1, max_threads = 1 kept.

Session id: cron:clickhouse-impl-slot-40:20261122-183700

@clickhouse-gh

clickhouse-gh Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cba2dac]

Summary: ✅


AI Review

Summary

PR #133621 replaces six layout-sensitive performance queries with larger-group equivalents while preserving their historical indices. The reported cross-build comparisons and per-site regression measurements support the stability improvement and retained regression sensitivity. Review of head cba2dac905be39d6c00ef63b21aab82a3853293c, the current aggregation paths, harness, and prior discussion found no actionable issues.

Missing context / blind spots
  • ⚠️ Benchmarks were not independently rerun because this checkout has no server binary or build. CI performance comparisons were pending or skipped at review time; completed performance reports would provide independent confirmation of the supplied measurements.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). can be tested Allows running workflows for external contributors labels Nov 22, 2026
@alexey-milovidov alexey-milovidov self-assigned this Nov 23, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 23, 2026
Merged via the queue into ClickHouse:master with commit 0f72fc8 Nov 23, 2026
577 of 579 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 Nov 23, 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-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). 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