Repository navigation
Avoid double compression in adaptive codec selection - #113511
Conversation
Selection used to compress every compress-priced candidate into a temp buffer to measure it, then compress the winner again. Not anymore
|
Workflow [PR], commit [200615c] Summary: ✅
AI ReviewSummaryThis PR rewrites Findings
Tests
Final VerdictLLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 81/86 (94.19%) · Uncovered code |
| /// Compressed size of a single block as `compress` would produce it (block header + payload). | ||
| static UInt32 getCompressedBlockSize(const ICompressionCodec & codec, const char * src, UInt32 src_size, PODArray<char> & scratch); | ||
|
|
There was a problem hiding this comment.
No longer needs to be public after selection + compression fuse
There was a problem hiding this comment.
Better to move to the free function now
| return bytes; | ||
| } | ||
|
|
||
| /// Compress `bytes` with the adaptive codec for `type_name` and return the winner's on-disk method byte. |
There was a problem hiding this comment.
Small refactor, partly because we no longer can access getCompressedBlockSize
| <fill_query>OPTIMIZE TABLE adaptive_codec_merge FINAL</fill_query> | ||
|
|
||
| <!-- 1 -> 1 merge --> | ||
| <query>OPTIMIZE TABLE adaptive_codec_merge FINAL</query> |
There was a problem hiding this comment.
This adds the benchmark harness, but the PR still lands without any measured before/after result for the optimization it is claiming. The performance-comparison shards for this PR were skipped, so reviewers cannot verify that the new selection path actually improves the common "default codec wins" merge case in practice. Please run the performance job (or attach an equivalent benchmark result) and point to the numbers here.
There was a problem hiding this comment.
The performance-comparison shards for this PR were skipped, so reviewers cannot verify that the new selection path actually improves the common "default codec wins" merge case in practice
The CI is still running...
|
|
||
| <!-- The default codec wins every block --> | ||
| <fill_query>SYSTEM STOP MERGES adaptive_codec_merge</fill_query> | ||
| <fill_query>INSERT INTO adaptive_codec_merge SELECT cityHash64(number % 1024) FROM numbers_mt(400000000)</fill_query> |
There was a problem hiding this comment.
2.6s in CI – not perfect, but ok. I'll halve it (perhaps in follow-up)
Michicosun
left a comment
There was a problem hiding this comment.
Maybe something like https://pastila.nl/?00166002/5a401f2a45ce24a4c82dbcfda357a5f2#GTyMpl5bH7iAn3/mO7R0zQ==GCM will be more understandable
| /// Compressed size of a single block as `compress` would produce it (block header + payload). | ||
| static UInt32 getCompressedBlockSize(const ICompressionCodec & codec, const char * src, UInt32 src_size, PODArray<char> & scratch); | ||
|
|
There was a problem hiding this comment.
Better to move to the free function now
| if (scratch.empty()) | ||
| scratch.resize_exact(getMaxCompressedDataSize(source_size)); |
There was a problem hiding this comment.
not needed, resize_exact will check the same
rienath
left a comment
There was a problem hiding this comment.
Thank you. I addressed all the comments and switched to multiplexer approach you proposed. I slightly simplified it
| /// Compressed size of a single block as `compress` would produce it (block header + payload). | ||
| static UInt32 getCompressedBlockSize(const ICompressionCodec & codec, const char * src, UInt32 src_size, PODArray<char> & scratch); | ||
|
|
|
|
||
| <!-- The default codec wins every block --> | ||
| <fill_query>SYSTEM STOP MERGES adaptive_codec_merge</fill_query> | ||
| <fill_query>INSERT INTO adaptive_codec_merge SELECT cityHash64(number % 1024) FROM numbers_mt(400000000)</fill_query> |
| if (scratch.empty()) | ||
| scratch.resize_exact(getMaxCompressedDataSize(source_size)); |
| <create_query> | ||
| CREATE TABLE adaptive_codec_merge (x UInt64) | ||
| ENGINE = MergeTree ORDER BY tuple() | ||
| SETTINGS allow_experimental_adaptive_codec_selection = 1 |
There was a problem hiding this comment.
This benchmark is supposed to measure the "deployment default codec wins" case, but the table leaves default_compression_codec to the server default. In CI that setting is randomized across LZ4, ZSTD(1), and ZSTD(3) by tests/config/install.sh, and tests/performance/scripts/perf.py just executes the <create_query> verbatim, so performance runs do not get the tests/clickhouse-test LZ4 pin that .sql tests with no-random-merge-tree-settings rely on.
On runs where the default is ZSTD, this stops exercising the path this PR is optimizing and makes the before/after delta configuration-dependent. Please pin default_compression_codec = 'LZ4' (or whichever default you want to study) in the table settings.
There was a problem hiding this comment.
We don't randomise .xml tests
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units10 translation units recompiled, 18 s compile time in total, 10 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
Since ClickHouse#113511 selection compresses each candidate at most once, so the isCandidateType saves nothing. Types with no specialized candidate now get NONE / default codec
Adaptive compression used to have two phases: selection and compression. During selection, we compressed every candidate that cannot report its compressed size cheaply into a temporary buffer to measure it. If such a candidate won, the compression phase then compressed it again.
This fuses selection into compression. We do a single pass in which candidates with cheap sizing are only measured, and the rest compress into
dest, or into a scratch buffer whendestholds the best result so far. After the pass the winner reachesdestone of three ways: it is already there, it is copied from scratch, or, for a measured-only winner, it is compressed now, for the first and only time. With today's pool this halves the compression work whenever the default codec wins a block.Not for changelog because adaptive compression is released in 26.8 (#111834).
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Adaptive codec selection now compresses with each candidate codec at most once per block instead of measuring all candidates and then recompressing the winner.
Workflow [PR]
Sync PR [sync-upstream/pr/113511]
Version info
26.8.1.1671(included in26.8and later)