Skip to content

Use a short String payload and fewer run lengths in the sparse_column_index_runs performance test - #129399

Draft
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/sparse-column-index-runs-short-payload
Draft

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/sparse-column-index-runs-short-payload

Conversation

@groeneai

@groeneai groeneai commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #100759
Related: #118237

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 sparse_column_index_runs performance test uses short String values, so its queries no longer run at a different speed on each of the two servers of a comparison, and it keeps run lengths 1, 2 and 64 only.

Description

sparse_column_index_runs #3-#5 (run lengths 8, 16, 64) are noisy on amd: from 2026-10-25 to 11-04 the two servers' medians differed by more than 10% in 26%, 36% and 17% of master jobs (arm: under 1%). Example: amd_release 1/6. Each server keeps its own level for the whole job (in-run CV ~2%); the same binary gives uncorrelated levels in consecutive jobs (r = -0.01 over 457 shas).

CI's own CPU profiles of the slower server put 85% of its extra samples in memcpy inside jemalloc realloc, 94% of them growing the chars of the String result of ColumnSparse::index (ColumnString::insertManyFrom); per job, the difference in that share predicts the time ratio (r = 0.81). With the 385-448 byte payload every 65409-row output block builds ~1.26 MB of chars by doubling, and whether jemalloc can grow it in place depends on the process's heap layout.

The payload is now toString(number) (1-7 bytes), so a block's chars fit in one 32 KiB allocation. Tables, rows and sparse layout are unchanged, and both columns still take the run path.

Run lengths 4, 8 and 16 are removed: only run length 1 takes the single-row insertFrom path, and 2 to 64 all take the same run path (one lookup and one insertManyFrom per run), differing only in rows per run. Run length 64 moves from #5 to #2, so it is judged at the 0.15 floor until its new key has history.

Validation: two local servers, official master amd_release binary, CI config and pinning, 12 fresh processes per variant. Old: CV of the per-process medians 4.7% / 8.6% / 4.5% for #3-#5. New: 1.5% / 1.0% / 1.4%, no server pair over 2.5% apart. perf.py runs the new file with rc 0, and its queries are byte-identical to the old #0, #1, #5.

🤖 Generated with Claude Code


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

Queries ClickHouse#3-ClickHouse#5 of this test were noisy on amd: in 16-36% of master jobs the
two servers' medians differed by more than 10%, while each server stayed at
its own level for the whole job (in-run CV ~2%).

The level belongs to the server process, not the binary or the data. CI's
own CPU profiles of the slower server attribute 85% of its extra samples to
memcpy inside jemalloc realloc, 94% of it growing the chars of the String
result of ColumnSparse::index (ColumnString::insertManyFrom ->
PODArray realloc). With a 385-448 byte payload every 65409-row output block
materializes ~1.26 MB of chars, grown by doubling; whether jemalloc can grow
such an allocation in place depends on the process's heap layout, so a
process is fast or slow for its whole life.

toString(number) keeps the same tables, rows, sparse layout and run
structure, and both String and UInt64 still go through the run path of
ColumnSparse::index; only the bytes copied per String value shrink.

Related: ClickHouse#100759
Related: ClickHouse#118237

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

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @egor-click, could you review this and add the can be tested label so CI runs? Queries #3-#5 ran at a different speed in each server process on amd: the String result of ColumnSparse::index grew ~1.26 MB of chars per block by realloc, and how much of that is copied depends on the process's heap layout (85% of the slower server's extra CPU samples), so this PR shortens the test's String payload.

@fallintoplace, the values are now toString(number) instead of 64 repetitions of it, with the same tables, rows, sparse layout, run lengths and queries, and String and UInt64 still go through the run path of ColumnSparse::index. Is the short payload fine for what this test should cover (yes/no)?

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fbcedfe]

Summary: ✅


AI Review

Summary

This PR reduces noise in sparse_column_index_runs by shortening the generated String payload and retaining run lengths 1, 2 and 64. The reported measurements support the noise reduction while the retained cases preserve coverage of scalar and repeated-run insertion. The query renumbering tradeoff was explicitly discussed and accepted by a maintainer. No actionable findings in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 4, 2026
@Algunenano Algunenano self-assigned this Nov 5, 2026

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai Looks good, but do we need 6 different run_length values? It might make sense to drop some of them if they are testing the same thing

Run length 1 is the only one that takes the single-row insertFrom path of
ColumnSparse::index. Every length from 2 to 64 takes the same run path
(one value lookup and one insertManyFrom per run) and differs only in how
many output rows share a run, which master CI shows as a smooth curve
(amd medians 117 / 81 / 58 / 49 / 35 ms for 2 / 4 / 8 / 16 / 64). Keep the
shortest and the longest run next to the control and drop 4, 8 and 16.

Queries #0 and ClickHouse#1 keep their index and text; run length 64 moves from ClickHouse#5
to ClickHouse#2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Use a short String payload in the sparse_column_index_runs performance test Use a short String payload and fewer run lengths in the sparse_column_index_runs performance test Nov 5, 2026
@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

No. Only run_length = 1 takes a different path in ColumnSparse::index (the single-row insertFrom). 2 to 64 all take the same run path (one value lookup and one insertManyFrom per run) and only change the number of rows per run; on master they form a smooth curve (amd 117 / 81 / 58 / 49 / 35 ms). I kept 1, 2 and 64 and dropped 4, 8 and 16 in b462a98. Run length 64 moves from #5 to #2.

@egor-click

Copy link
Copy Markdown
Contributor

we have only test and query number for historical results, if we start deleting tests, all query numbers will change and all history we have will be thrown into trash

i don’t like that, @groeneai , this is a solution made in a hurry that will break more than it will improve

i think that we need a way to mark queries disabled,stale so they don't run and only append new queries or create new tests and never change or delete

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Understood. Here the payload change keeps every query number; the only renumbering is b462a98, which dropped run lengths 4, 8 and 16 at @ Algunenano's request and moved 64 from #5 to #2. I can revert that commit so no number moves, or keep it, and I won't push to this PR until you and @ Algunenano agree. A disabled marker looks small in perf.py: the query number is the position in the expanded query list, so a disabled query that keeps its slot but is not run leaves every other number unchanged. I can send it as a separate PR if you want it.

@Algunenano

Copy link
Copy Markdown
Member

@egor-click We modify bad performance tests all the time. Keeping a bad test history does not make sense. We also constantly remove / add new queries in existing performance tests, so keeping improvements behind the idea of having a perfect history is not even a reality today. Let's drop bad unnecessary tests. If we need history, why not use the hash of the query instead of comparing test file + query number?

@Algunenano

Copy link
Copy Markdown
Member

Let's wait until @egor-click reworks the history before changing any performance tests queries. We can fix other things (like preventing new bad tests being included in the meantime)

@Algunenano
Algunenano marked this pull request as draft November 5, 2026 14:41
@Algunenano Algunenano assigned egor-click and unassigned Algunenano Nov 5, 2026
@clickhouse-gh clickhouse-gh Bot added comp-datatype-wrapper Type modifiers/wrappers (Nullable, LowCardinality, etc.). and removed comp-testing Test content only (no production code). labels Nov 19, 2026

This branch has not been deployed

No deployments
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-datatype-wrapper Type modifiers/wrappers (Nullable, LowCardinality, etc.). pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants