Skip to content

Speed up estimateCompressionRatio for T64-encoded columns - #109054

Merged
rienath merged 7 commits into
masterfrom
faster-comp-estimation
Jul 18, 2026
Merged

rienath merged 7 commits into
masterfrom
faster-comp-estimation

Conversation

@rienath

@rienath rienath commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

It now computes the compressed size analytically instead of compressing, with the same result.

Under the hood this adds a codec size primitive, ICompressionCodec::tryGetCompressedSize (exact size, or std::nullopt when it cannot be computed cheaply), and a CompressedSizeCalculator buffer that uses it. This is the "measured size" primitive from the adaptive codec selection RFC (#105404), which the per-block selector will use to compare candidates. Adaptive selection itself is not part of this PR, but the infrastructure added in this PR is a must for it.

image

Changelog category (leave one):

  • Performance Improvement

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

Speed up estimateCompressionRatio for T64-encoded columns by computing the compressed size analytically instead of compressing.

Version info

  • Merged into: 26.7.1.1161 (included in 26.7 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0448fda]

Summary: ✅


AI Review

Summary

This PR replaces the aggregate's CompressedWriteBuffer path with CompressedSizeCalculator, adds an exact tryGetCompressedSize implementation for T64, and extends coverage for the signed cross-zero and misaligned-block cases. The refactor keeps the analytical-size path aligned with the real T64 encoder by sharing the same layout computation, and the updated tests cover the edge cases that mattered here, so I did not find any remaining correctness, coverage, or PR-metadata issues.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jul 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

This PR is scoped entirely to the T64 compression codec (adding tryGetCompressedSize) and the estimateCompressionRatio aggregate (a new CompressedSizeCalculator), plus tests. None of the three flagged queries exercise those code paths: ClickBench Q15 and Q32 and TPC-H Q4 are ordinary SELECTs over standard-codec data that never call estimateCompressionRatio. The ClickBench deltas were already suppressed/held as noise deterministically, and I downgraded the flagged TPC-H Q4 regression (+7.4%) to not_sure because the diff cannot touch what it runs and that query is intrinsically noisy. No genuine PR-attributable regression or improvement is visible in these results.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 32 not_sure 1312 1438 +9.6% 0.0014 Q32 does not exercise the T64 codec or estimateCompressionRatio, so the +9.6% is off-path run-to-run variance, consistent with the mixed signals from the two tests. not_sure stands.

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_official

⚠️ 1 inconclusive

Flagged queries (1 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 4 not_sure 1026 1101 +7.4% <0.0001 The changes are confined to the T64 codec and the estimateCompressionRatio aggregate; TPC-H Q4 runs neither (standard-codec data, no compression-estimate call), so the +7.4% cannot be caused by this PR. History is noisy, so this is variance.

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
  • StressHouse run: 892213c1-60db-4c98-8146-63ae1e089d95
  • MIRAI run: 38ec40d3-5b38-4cf6-980c-1b2c0f29d816
  • PR check IDs:
    • clickbench_80991_1784306290
    • clickbench_81004_1784306290
    • clickbench_81011_1784306290
    • tpch_adapted_1_official_81017_1784306290
    • tpch_adapted_1_official_81026_1784306290
    • tpch_adapted_1_official_81038_1784306290

@Michicosun Michicosun self-assigned this Jul 6, 2026
Comment thread src/Compression/CompressionCodecT64.cpp Resolved
Comment thread src/Compression/CompressionCodecT64.cpp Resolved
Comment thread src/Compression/CompressionCodecT64.cpp Resolved
Comment thread src/Compression/CompressionCodecT64.cpp Resolved
Comment thread src/Compression/CompressionCodecT64.cpp Resolved

@rienath rienath left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the detailed review, I addressed all the comments.

Comment thread src/Compression/CompressionCodecT64.cpp Resolved
Comment thread src/Compression/CompressionCodecT64.cpp Resolved
Comment thread src/Compression/CompressionCodecT64.cpp Resolved
Comment thread src/Compression/CompressionCodecT64.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.00% 86.00% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 78.10% 78.20% +0.10%

Changed lines: Changed C/C++ lines covered: 159/183 (86.89%) · Uncovered code

Full report · Diff report

@rienath
rienath added this pull request to the merge queue Jul 18, 2026
Merged via the queue into master with commit bd0f951 Jul 18, 2026
350 of 351 checks passed
@rienath
rienath deleted the faster-comp-estimation branch July 18, 2026 22:53
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 18, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…mation

Speed up `estimateCompressionRatio` for `T64`-encoded columns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants