Repository navigation
Enable libc++ hardening in all source files - #133805
Algunenano merged 14 commits into
Conversation
The window function TUs have no hardening checks in hot loops after the rewrite, except `WindowArguments::at`. Keep the check on the data-dependent block lookup there and drop the ones on the argument index, which is checked by `chassert`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`hashjoin_with_large_output` and the row store join tests show no difference now. Check the row range in `gatherColumnFromRows` once instead of for every row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Index the per-column vectors through `data` in the row loops of `FunctionArray`. They have an element for every column, so the checks there only repeated the loop bound. Co-Authored-By: Claude Opus 5.5 <[email protected]>
It holds only tree building and iteration; `range_hashed_dictionary` shows no difference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With libc++ hardening `buildTree` no longer inlined this helper, and the per-element `emplace_back` made loading a `range_hashed` dictionary 10% slower. Now it is 2%. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`range_hashed_dictionary` shows no difference, and lookups have the same instruction count. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the simple key data pointer in `DictionaryKeysExtractor` and hoist the shard container and nullable set pointers out of the lookup loops. The checks in the loop body stopped the per-key lambda of `hasKeys` from being inlined. `dictHas` is now 8-16% faster on sparse dictionaries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hoist the shard container pointers out of the key lookup loops. Also restore `-g1` for `HashedDictionary.cpp` and `RangeHashedDictionary.cpp`, which was lost together with their hardening exclusion. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`destroy_aggregate_states` and the `GROUP BY` tests show no difference when only this TU changes. This removes the last per-TU hardening exclusion. Co-Authored-By: Claude Opus 5.5 <[email protected]>
It scans the vector of bools word by word, without a bounds check for every row. `row_number` and `ntile` over a single partition run 4-6% fewer instructions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [3902161] Summary: ❌
AI ReviewSummaryEnables libc++ hardening across ClickHouse source files and adjusts hot loops to control its cost. No actionable findings remain at head Missing context / blind spots
Final VerdictStatus: ✅ Approve |
…nts::at` Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Commit See the job log for details. |
With libc++ hardening in `Aggregator.cpp` it was no longer inlined into the aggregation loop, which made `String` key `GROUP BY ... LIMIT` with the top-K heap 1.2x slower on ARM. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
With libc++ hardening, `Partition::advance` calls `std::find` out of line, so it saves and restores registers on every call. `beginAt` calls it once per row when every partition has one row, which made `window_function_with_order` 8-15% slower. `beginAt` now finishes the partition directly when the next row starts a new one; on ARM these queries are now 2-6% faster than master. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133805&sha=aaafc36b8dd044fc35fd92cecfc69888103a15c6&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%201%2F8%29 PR: ClickHouse#133805 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Force-inlining `TopKAggregationHeapBase::shouldSkip` made `shouldSkipTyped` too big to inline, so `String` key `GROUP BY ... LIMIT` with the top-K heap still called it per row and stayed 1.2x slower on ARM. For key methods without typed key data `shouldSkipTyped` always falls through to `shouldSkip`, so the call sites now use `shouldSkip` directly; `optimize_trivial_group_by_limit` queries 6 and 7 are back to the master timings. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133805&sha=aaafc36b8dd044fc35fd92cecfc69888103a15c6&name_0=PR PR: ClickHouse#133805 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The remaining regression in We are merging this PR now to help advance other PRs, like CFI and other hardening work, that hit similar hotspots. |
23b95d8
| @@ -15,6 +17,16 @@ void Partition::beginAt(const SlidingBlocks & blocks, RowNumber first_row) | |||
| partition_bounds.rows_count = 1; | |||
| partition_bounds.start_visible = true; | |||
| partition_bounds.end_visible = false; | |||
|
|
|||
| /// Single-row partitions call this once per row. Their end is visible right away, so this check keeps `advance`, which | |||
There was a problem hiding this comment.
This is a hack. Why do we need to do it this way?
There was a problem hiding this comment.
The first hack was to disable hardening. This enables it back without reverting the PR that introduced this
There was a problem hiding this comment.
It was introduced starting with the development of window functions, so probably 7 years ago
It is not possible to revert
`Performance Comparison (arm_release, master_head, 4/8)` on 095e311 marked `optimize_trivial_group_by_limit` ClickHouse#6 and ClickHouse#7 (`String` key, no `COLLATE`) as confirmed regressions: 50 -> 59 ms (+18%). The loops of the methods without a typed key called `shouldSkipTyped` out of line on every row; master fixed that the same way in ClickHouse#133805 (`shouldSkip` forced inline and called directly), which the previous merge brings in. What remains of this PR in those loops is the `has_collators` branch of the force-inlined `shouldSkip`. It inlined both collated comparators into every loop. They now live in an out-of-line `shouldSkipCollated` (`NO_INLINE`, so that ThinLTO does not import it either), so the loops get a branch and a cold call, the shape the PR had at 1a5e9ec, where arm measured ClickHouse#6/ClickHouse#7 at 52 -> 51 ms. Local release builds (no ThinLTO/PGO), 8 threads, medians of 42 runs, ms, master 290fa0d / merge without this / with this: - ClickHouse#6: 56.5 / 59 / 59 - ClickHouse#7: 58 / 58.5 / 59 - ClickHouse#7 without `count()`: 57.5 / 56.5 / 56 - numeric key: 39 / 37 / 37 Before the merge, 095e311 measured ClickHouse#7 at 64 ms against master's 61. The collated queries do not change: 1K keys in cycles at 12 threads 115 -> 114 ms, 20M unique keys 38 -> 38 ms; `hits` `URL ... COLLATE 'en' LIMIT 10` at 12 threads, measured on 095e311 before the merge: 598-608 -> 579-622 ms, 61 MB both. Related: ClickHouse#126735 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #94757
Remove all per-TU libc++ hardening exclusions (29 files: window functions,
Aggregator.cpp,IColumn.cpp,IntervalTree.cpp,array.cpp, hashed/hashed array/range hashed dictionaries). Hot loops that paid for bounds checks are fixed instead, keeping checks on data-dependent indices:WindowArguments::at: no checks on the argument index in the fast path.gatherColumnFromRows,FunctionArray,HashedDictionary,HashedArrayDictionary: check once outside the row loop. InhasKeysthe checks stopped the per-key lambda from being inlined (+22% cycles); now sparsedictHasis 8-16% faster than before.IntervalTree::intervalsToPoints: dictionary load was 10% slower becausebuildTreestopped inlining it.Partition::advance:std::findover the bool vector, 4-6% fewer instructions forrow_number/ntile.Each file is a separate commit. Also restores
-g1forHashedDictionary.cppandRangeHashedDictionary.cpp, which was tied to the exclusion list.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
libc++ hardening is now enabled for all ClickHouse source files, including the ones where it was disabled for performance.
Workflow [PR]
Sync PR [sync-upstream/pr/133805]
Version info
26.12.1.425-master(included in26.12and later)