Skip to content

Fill values_index in ColumnSparse::indexImpl by scattering offsets - #128852

Merged
Blargian merged 1 commit into
masterfrom
sparse-index-scatter-offsets
Nov 9, 2026
Merged

Blargian merged 1 commit into
masterfrom
sparse-index-scatter-offsets

Conversation

@thevar1able

@thevar1able thevar1able commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

The loop that materializes a value index for every row compared each row with the next offset through Iterator::getValueIndex. clang 22 compiles that into a well-predicted branch; clang 23 if-converts it into cmov, which puts the load of the offsets on a loop-carried dependency chain (sparse_column_index_runs 18-21% slower in #117346). Zero-fill the array and scatter i + 1 at each offset instead: O(size + offsets), every offset touched once, no per-row branch or cmov at all, so neither compiler can pessimize it.

Related: #117346

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Slightly faster index of sparse columns.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.1748-master (included in 26.11 and later)

…s instead of walking the iterator

`sparse_column_index_runs` is 18-21% slower with `clang-23`, all of it in
`ColumnSparse::index`. The loop that materializes a value index for every
row compared each row with the next offset through `Iterator::getValueIndex`;
`clang-22` compiled that into a well-predicted branch (most rows are
defaults), `clang-23` if-converts it into `cmovne`/`sete`, which puts the
load of `offsets[current_offset]` on a loop-carried dependency chain and
serializes the loop at the load latency.

Zero-fill the array and scatter `i + 1` at each offset instead. That is
O(size + offsets), touches every offset once and has no per-row branch or
`cmov` at all, so neither compiler can pessimize it.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117346&sha=4a12a96fba025fb6340160f135a68025f4da2464&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%202%2F6%29
Related: #117346

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

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b56d81d]

Summary: ✅


AI Review

Summary

Replaces the row-by-row lookup construction in ColumnSparse::indexImpl with zero initialization followed by scattering non-default value indexes. No new correctness finding identified, but the claimed performance improvement still needs measurements before approval.

Tests
  • ⚠️ The Performance Improvement claim has no before/after measurement for this patch. The linked compiler-upgrade PR establishes the original slowdown, while this PR's performance jobs are still PENDING and the performance dashboard has no run. Provide results from the existing sparse_column_index_runs benchmark, comparing the iterator and scatter implementations with the same compiler. To substantiate the stated benefit across compiler versions, include clang-22 and clang-23 results across the existing run lengths; no additional benchmark is needed.
Final Verdict

Status: ⚠️ Request changes — supply before/after performance evidence for the claimed improvement. No new inline findings were posted.

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-datatype-wrapper Type modifiers/wrappers (Nullable, LowCardinality, etc.). labels Nov 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b56d81de6 with master f83293657 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 230ae8eec; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline.

Job report

@evillique evillique self-assigned this Nov 6, 2026
@thevar1able
thevar1able added this pull request to the merge queue Nov 9, 2026
@Blargian
Blargian removed this pull request from the merge queue due to a manual request Nov 9, 2026
@Blargian
Blargian added this pull request to the merge queue Nov 9, 2026
Merged via the queue into master with commit 6ab0967 Nov 9, 2026
180 checks passed
@Blargian
Blargian deleted the sparse-index-scatter-offsets branch November 9, 2026 16:35
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-datatype-wrapper Type modifiers/wrappers (Nullable, LowCardinality, etc.). pr-performance Pull request with some performance improvements 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.

4 participants