Skip to content

Four optimisations of T64 decompression - #120414

Merged
rienath merged 20 commits into
masterfrom
t64-performance
Sep 25, 2026
Merged

rienath merged 20 commits into
masterfrom
t64-performance

Conversation

@rienath

@rienath rienath commented Sep 16, 2026 •

Copy link
Copy Markdown
Member
  1. Unpack only the stored planes rather than always all. The new loops auto-vectorise both on x86 and arm.
  2. Fuse the byte-level reverse transpose, common-bit restoration and output writes into one pass per block.
  3. Decode blocks with one stored bit through a lookup table.
  4. Decode blocks with at most 8 stored bits through a 64-byte matrix instead of the 512-byte one, so unused planes are never cleared and zero high bytes are never rebuilt.

This PR is important for adaptive codec selection (enable_adaptive_codec_selection) as it relies on T64.

image

Changelog category (leave one):

  • Performance Improvement

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

Faster decompression of T64-encoded columns.


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

Version info

  • Merged into: 26.10.1.670-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0d31535]

Summary: ✅


AI Review

Summary

This PR rewrites the T64 decode kernels to avoid unnecessary plane work, adds a dedicated one-bit fast path, factors the transpose helpers into a shared header, and expands correctness coverage around the rewritten paths. The implementation looks coherent and the new tests materially reduce the risk of a codec regression, but I still cannot approve a PR labeled Performance Improvement without focused before/after evidence for the new T64 benchmark.

Findings
  • ⚠️ Majors
    • [dismissed by author -- https://github.com/Four optimisations of T64 decompression #120414#discussion_r4027882489] [tests/performance/codecs_t64_select.xml:74] The PR still does not show focused before/after numbers for the T64 decode workloads it claims to speed up. The only visible CI evidence here is the generic cloud benchmark no_change comment plus a Build profile diff, and neither demonstrates that the new decode paths are actually faster on the byte/bit cases added in this PR.
      Suggested fix: attach the Performance Comparison output for this PR once it is available, or paste focused before/after numbers from tests/performance/codecs_t64_select.xml.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Provide focused before/after performance evidence for the T64 decompression paths this PR claims to speed up.

LLVM Coverage Report

Measured on commit 0d31535.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 155/155 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... labels Sep 16, 2026

<fill_query>OPTIMIZE TABLE t64_select_{case} FINAL SETTINGS optimize_throw_if_noop=1</fill_query>

<query>SELECT count() FROM (SELECT n FROM loop(t64_select_uint8_one_byte) WHERE ignore(n) = 0 LIMIT 5367000000)</query>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This benchmark definition is useful, but the PR contract here is a measured Performance Improvement, not just a new perf test. During review the PR report still had the Performance Comparison shards pending and no uploaded all-query-metrics.tsv artifacts, so there is no before/after evidence yet that these new decode paths are a net win on the target architectures.

Please attach the perf-comparison output for this PR, or paste focused before/after numbers from this new benchmark in the PR description.

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.

Wait for CI to finish, duh

@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

Release-transition baseline: compared against the most recent available 26.9 masters at or before the trusted base-commit anchor because no 26.10 master baseline exists there.

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 4da14c55-1f60-4671-b009-5dcee6c537fb
  • MIRAI run: 5dc4f4c2-728b-4ac0-b066-bdb97ddc34f7
  • PR check IDs:
    • clickbench_1519983_1790181989
    • clickbench_1519996_1790181989
    • clickbench_1520001_1790181989
    • tpch_adapted_1_official_1520007_1790181989
    • tpch_adapted_1_official_1520039_1790181990
    • tpch_adapted_1_official_1520053_1790181990

@nikitamikhaylov

Copy link
Copy Markdown
Member

@4ertus2 FYI

@rienath
rienath added this pull request to the merge queue Sep 17, 2026
@rienath
rienath removed this pull request from the merge queue due to a manual request Sep 17, 2026
src += bytes_to_skip;
dst += bytes_to_skip;

if (uncompressed_size % sizeof(T) != 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why it's possible to remove it?

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.

Because a few lines above we have

UInt8 bytes_to_skip = uncompressed_size % sizeof(T);
...
uncompressed_size -= bytes_to_skip;

After that uncompressed_size % sizeof(T) is always 0

Comment thread src/Compression/CompressionCodecT64.cpp Outdated
@@ -415,6 +423,7 @@ void reverseTransposeBytes(const UInt64 * matrix, UInt32 col, T & value)
value |= static_cast<UInt32>(matrix8[64 * 1 + col]) << (8 * 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

64 * 1, (8 * 1)

these multiplication were self descriptive in original version. For now they look strange. You touch the code above them. Could you fix them too?

@rienath rienath Sep 18, 2026 •

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.

Sure thing, done

On O3 we'd get same instructions as with constexpr ladder
Comment thread src/Compression/CompressionCodecT64.cpp Outdated

template <typename T>
void reverseTransposeMatrixBytes(const UInt64 * matrix, T * buf, UInt32 tail)
T restoreUpperBits(T value, T upper_min, T upper_max, T sign_bit)

@4ertus2 4ertus2 Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As soon as you change it it's possible to improve its semantic.

Here #94499 it's possible to save not only upper bits but intermediates too. So it's better to rename this function:

T restoreCommonBits(T value, T common_negative, T common_positive, T sign_bit)

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.

Renamed

@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 0d31535868a89aaeaabdd8fdf1c77c6123fea1df was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@4ertus2

4ertus2 commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

It's really hard to check and approve the new SIMD logic.
I think the only way to really test it is to make more T64_CODEC_SIMD_TRANSPOSE cases for mixed compression-decompression cycles:
0 - no simd
1 - simd only in forward transpose (for test)
2 - simd only in reverse transpose (for test)
3 - simd in both directions (for release)

So there sould be a unit test with compression-decompression cycle for values 1 and 2. It will guaranty that no-simd version decompreses simd compression. And visa versa.

@rienath

rienath commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Went with a compile-time split. The transposes now are in a separate header with scalar and simd namespaces picked by a compile-time active alias. scalar is compiled unconditionally. All 4 cases are covered by tests @4ertus2

@rienath

rienath commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

@4ertus2 do you think this PR is ready to be shipped?

@4ertus2

4ertus2 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@4ertus2 do you think this PR is ready to be shipped?

LGTM

@rienath
rienath added this pull request to the merge queue Sep 25, 2026
Merged via the queue into master with commit 05d3fe5 Sep 25, 2026
346 of 349 checks passed
@rienath
rienath deleted the t64-performance branch September 25, 2026 13:11
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 25, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 26, 2026
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md.

Changelog-revert: 121902 121901 docs(managed-postgres): updated Private Service Connect
Changelog-revert: 122310 120414 Revert "Four optimisations of `T64` decompression"
Changelog-revert: 122326 115526 Revert "Publish a failing job step's cause to CIDB, not just the failure count"
Changelog-deleted-entry: 120414 [Performance Improvement] [raw] * Faster decompression of `T64`-encoded columns. [#120414](#120414) ([Raufs Dunamalijevs](https://github.com/rienath)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... 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