Repository navigation
Compare integer keys inline in sumMap, minMap and maxMap - #124340
alexey-milovidov merged 2 commits into
Conversation
The ordered map behind sumMap, sumMapWithOverflow, sumMapFiltered, minMap and maxMap is keyed by Field, so every array element costs a few calls to the out-of-line Field::operator< (41.8% of query 2 samples in tests/performance/sum_map.xml on x86, 55% on the arm CI profile). Use a comparator that compares UInt64 and Int64 keys inline and delegates every other pair to Field::operator<. It returns the same value as Field::operator< for every pair, so the iteration order, the results and the serialized state are unchanged. Measured (release, x86, max_threads=1, median of 15, 4 interleaved rounds): sum_map.xml queries 0..7 at 0.42x..0.53x of master time, Int64 keys 0.47x, sumMapFiltered 0.71x; String keys 1.06x (+4.4% instructions). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The per-comparison type check of the previous commit cost every other key type a few instructions per tree step (String keys: +4.4% instructions). Choose the comparator once, from the key type, when the function is created: native integer, Enum, Date, Date32 and DateTime keys use FieldLess, every other key type keeps std::less<Field>, so it runs the same code as before. Measured against master (release, x86, max_threads=1, median of 15, 4 interleaved rounds): sum_map.xml queries 0..7 at 0.43x..0.53x (gmean 0.47), Int64 keys 0.47x, Date keys 0.52x, sumMapFiltered 0.70x. String and Float64 keys: 0.99x and 1.03x wall, the same instruction count (1.000x). .text grows by 335,872 bytes (+0.07%). CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109369&sha=057d1a84efd5862b92d7cf35211c466cd4a3aa99&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%201%2F6%29 PR: ClickHouse#109369 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261007-000100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261006-232500 |
|
Workflow [PR], commit [d59da2e] Summary: ✅
AI ReviewSummaryThis PR specializes the ordered Final Verdict
LLVM Coverage ReportMeasured on commit d59da2e.
Changed lines: Changed C/C++ lines covered: 57/65 (87.69%) · Uncovered code |
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionSumMap.cpp.o |
1.57 MiB | 2.95 MiB | +1.38 MiB (+87.88%) |
719 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
7 translation units recompiled, 20 s compile time in total, 7 of them have a recent master baseline.
|
📊 Cloud Performance Report ✅ AI verdict: This PR only changes the sumMap, minMap and maxMap family of aggregate functions (and their MappedArrays, WithOverflow and Filtered variants). For integer-like keys they now use a dedicated comparator instead of the generic one. No ClickBench or TPC-H query in this run calls these functions. The two flagged rows, ClickBench Q16 (+10.0%) and Q18 (+13.3%), are plain GROUP BY/count() aggregations whose PR medians fall inside master's current range, so marking them not_sure is correct, and there is no code-path reason to contest that. This run shows no performance impact from the PR; a benchmark that calls sumMap with integer keys would be needed to measure the intended speedup. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
alexey-milovidov
left a comment
There was a problem hiding this comment.
LGTM. However, I didn't understand why the new comparator is faster than the generic one. Can the generic one be improved the similar way?
|
The generic comparator is slow here because of the call, not the comparison. The generic one can get the same fast path: an inline same-type |
Performance Comparison (arm_release, master_head, 1/6)on #109369 reportedsum_mapquery 2 (sumMap(key, val)over arrays) as slower: https://s3.amazonaws.com/clickhouse-test-reports/PRs/109369/057d1a84efd5862b92d7cf35211c466cd4a3aa99/pr/performance_comparison_arm_release_master_head_1_6/report.html. That PR does not touch this code. In the job's profile, 55% of the samples are inField::operator<, called for every array element by the orderedFieldmap inAggregateFunctionMapBase::add. The call is out-of-line, so its cost moves with code placement, and this test reports "slower" on many unrelated PRs.This change gives the map, and the key set of
sumMapFiltered, a comparator that comparesUInt64andInt64fields inline and callsField::operator<otherwise. It returns the same value asField::operator<for every pair, so the order, the results and the serialized state do not change. The comparator is chosen once from the key type: native integer,Enum,Date,Date32andDateTimekeys use it, and every other key type keepsstd::less<Field>, which runs the same code as before.Release build, x86,
max_threads = 1, median of 15 runs, time relative to master:sum_map.xmlqueries 0..7Int64keysDatekeyssumMapFilteredStringkeysFloat64keys.textgrows by 335,872 bytes (+0.07%). #107554 is the larger typed-aggregation rewrite of these functions, and this change does not replace it.Related: #109369
Related: #107554
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
sumMap,minMap,maxMap,sumMapWithOverflowandsumMapFilteredover arrays are up to 2.3 times faster for integer,Enum,Date,Date32andDateTimekeys.Workflow [PR]
Sync PR [sync-upstream/pr/124340]
Version info
26.10.1.1719-master(included in26.10and later)