Repository navigation
Improve ColumnVector::getExtremes for floating point - #111221
Conversation
ColumnVector::getExtremes for floating point numbersColumnVector::getExtremes for floating point
|
Workflow [PR], commit [16b7462] Summary: ✅
AI ReviewSummaryThis PR switches Findings💡 Nits
Final VerdictNon-blocking. The production LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 50/54 (92.59%) · Uncovered code |
| */ | ||
| if constexpr (has_find_extreme_implementation<T> && is_floating_point<T>) | ||
| { | ||
| auto cur_min = findExtremeMin(data.data(), start, end); |
There was a problem hiding this comment.
Have you tested if other types with has_find_extreme_implementation benefit from using findExtremeMin/findExtremeMax too?
There was a problem hiding this comment.
I spent a moment to get a better understanding for this. Thank you for asking.
Integers do not benefit much from using the find extreme implementation. The main difference between both is that the current implementation here is accumulating min and max in a single pass.
findExtreme() in contrast is doing two passes (one for min, one for max) and it implements a manually unrolled multi-accumulator reduction.
i.e. it sets up n accumulators and makes each accumulator consume only every n-th element. This enables the compiler either to reorder instructions more flexibly (due to the separate data dependencies) or to keep both data and accumulators in simd registers and thus auto-vectorize it.
This cannot be done automatically otherwise by the compiler because of IEEE semantics. It would requre --ffast-math for that.
For integers however the compiler can already do that automatically, so there's no opportunity to be more efficient with a manual implementation.
Big integers unfortunately lack comparison instructions for 128 bit and 256 big it seems, so no gain here as well.
| } | ||
|
|
||
| size_t i = start; | ||
| if constexpr (is_floating_point<T>) |
There was a problem hiding this comment.
Maybe we can implement has_find_extreme_implementation for BFloat16 in the near future and simplify this code, so we don't have 3 different if constexpr (is_floating_point<T>)
There was a problem hiding this comment.
Good point! Let's do it as a follow up and in the mean time briefly investigate already how much effort, complexity that'd be
|
📊 Cloud Performance Report ✅ AI verdict: The only runtime change in this PR is a vectorized getExtremes fast-path for floating-point columns; everything else is a new local benchmark tool, build wiring, unit tests, and a perf-test fixture. None of the flagged clickbench or TPC-H queries request extremes or hit that float path, so the +5% to +12% deltas are not plausibly caused by the diff. Q16's flagged regression is downgraded to not_sure on that basis, and the two envelope-suppressed rows (clickbench Q34, tpch_adapted_1_official Q7) are correctly suppressed — both medians sit inside master's current variance band, and the two TPC-H queries additionally ran co-located on a single node, which can inflate apparent deltas. Treat all four as run-to-run variance. clickbenchFlagged queries (3 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_officialFlagged queries (1 of 22)
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. Debug info
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 50/54 (92.59%) · Uncovered code |
Building master with -DENABLE_BENCHMARKS=ON failed to compile src/Storages/benchmarks/benchmark_statistics.cpp with two errors of the form "template argument for template type parameter must be a type" at lines 48 and 50. Two changes landed from branches that never saw each other. ClickHouse#109831 (ea66303) gave AggregateFunctionUniqCombined a ColumnType template parameter in second position, making it template <typename T, typename ColumnType, UInt8 K, typename HashValueType> ClickHouse#111221 (40da35b, "Reduce binary size for microbenchmark") then replaced registerAggregateFunctions() in this benchmark with a benchmark-local factory that hand-instantiates the class using the old three-argument spelling. The literal 12 therefore binds to the ColumnType position, where a type is required. Supply the missing argument at the two call sites, using the spelling the real factory uses for numeric types (AggregateFunctionUniqCombined.h:373, ColumnVector<TYPE>). This is behaviour-preserving rather than a choice among candidates: before ClickHouse#109831 the class hardcoded assert_cast<const ColumnVector<T> &>(*columns[0]) in its body, and that commit only hoisted the hardcoded type into the new parameter. No CI job caught this because ENABLE_BENCHMARKS defaults to OFF (CMakeLists.txt:159) and grep -rn ENABLE_BENCHMARKS ci/ returns no hits, so no build compiles this translation unit. Validated in both directions: on the unmodified tree the target fails with exactly those two errors and no others; with this change it compiles, links, and the four UniqV2 benchmark cases run, covering both the UInt64 and Float64 paths. The other eight benchmark targets compile cleanly, so all nine benchmark executables now build. Closes: ClickHouse#116251
Improve
ColumnVector<T>::getExtremes()performance for floating-point columns by using the existing optimizedfindExtremeMin()/findExtremeMax()helpers forFloat32/Float64.This affects column statistics that compute min/max over numeric columns, especially:
Motivation
Insert-time materialized statistics showed a large gap between integer and Float64 columns. For 65k rows, Float64
STATISTICS(minmax) was around an order of magnitude slower than UInt64, because ColumnVector::getExtremes() used ascalar NaN-aware loop for floats.
Changes
columns.
tests.
Results
Microbenchmark, 65,536 rows:
uniq_v2 did not show a Float64-specific slowdown; UInt64 and Float64 were comparable.
Testing
Ran:
Also validated the performance XML parses successfully.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve efficiency of minmax and basic column statistics for floating point columns.
Version info
26.8.1.1205(included in26.8and later)