Skip to content

Keep the sequence decoder locals uninitialized under -ftrivial-auto-var-init - #6

Open
groeneai wants to merge 1 commit into
ClickHouse:clickhousefrom
groeneai:uninitialized-sequence-decoder-locals
Open

groeneai wants to merge 1 commit into
ClickHouse:clickhousefrom
groeneai:uninitialized-sequence-decoder-locals

Conversation

@groeneai

Copy link
Copy Markdown

ClickHouse builds with -ftrivial-auto-var-init=zero in ClickHouse/ClickHouse#127909. With it, clang zero-fills seqState, the sequences ring and the decoded seq_t temporaries in the sequence decoders, and that changes how they are compiled: on arm_release the Performance Comparison shows codecs_float_select meta#11 +24% and ip_trie #2 +18%, both decoding ZSTD.

Every byte of these locals is written before it is read, so this marks them with a new ZSTD_UNINITIALIZED (__attribute__((uninitialized)), empty where the attribute is unsupported). With clang 22, ZSTD_decompressSequences, ZSTD_decompressSequencesSplitLitBuffer and ZSTD_decompressSequencesLong then compile to the same code as without the flag on aarch64 and x86-64 (object-level disassembly compared with the CI compile lines). Builds without the flag are unchanged.

Decompressed output is identical (zstd CLI levels 3 and 19 with a 128 MiB window, and a ClickHouse ZSTD column), and ClickHouse/ClickHouse#127909 pins this commit so that its Performance Comparison measures it.

…ar-init

ClickHouse builds with -ftrivial-auto-var-init=zero. With it, clang zero-fills
`seqState`, the `sequences` ring and the decoded `seq_t` temporaries in the
sequence decoders, which changes how they are compiled. On aarch64 that makes
decoding slower: up to +24% in the ClickHouse performance tests
codecs_float_select and ip_trie (ClickHouse/ClickHouse#127909).

Every byte of these locals is written before it is read, so mark them with a new
ZSTD_UNINITIALIZED (`__attribute__((uninitialized))`, empty where unsupported).
With clang 22, ZSTD_decompressSequences, ZSTD_decompressSequencesSplitLitBuffer
and ZSTD_decompressSequencesLong then compile to the same code as without the
flag, on both aarch64 and x86-64. Builds without the flag are not affected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 28, 2026
…init=zero`

The remaining arm_release slowdowns on this PR come from contrib code:
`codecs_float_select` ClickHouse#11 (+24%) and `ip_trie` ClickHouse#2 (+18%) decode `ZSTD`, and
`collations` ClickHouse#1 (+16%) compares strings with ICU.

- contrib/zstd -> ClickHouse/zstd#6 (0c4a7b5): `seqState`, the
  `sequences` ring and the decoded `seq_t` temporaries of the sequence decoders.
  `ZSTD_decompressSequences`, `...SplitLitBuffer` and `...Long` then compile to
  the same code as without the flag on aarch64 and x86-64.
- contrib/icu -> ClickHouse/icu#3 (e16b61b): the two collation
  iterators of the UTF-8 `RuleBasedCollator::doCompare`, 400 or 496 bytes each,
  zero-filled on every comparison that leaves the Latin fast path.

Local amd64 release builds, flag only vs with these annotations (max_threads=1,
3 x 7 runs): ORDER BY ... COLLATE 'tr' on 2M Cyrillic strings 0.131 s -> 0.113-0.119 s;
the ZSTD Float64 scan returns to 0.183 s, as without the flag (0.164 s with it).
Query results are identical (8 collations, zstd levels 3 and 19 with a 128 MiB window,
a ZSTD MergeTree column).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
motsc
motsc previously approved these changes Oct 29, 2026
@motsc
motsc dismissed their stale review October 29, 2026 15:02

AI-generated approval submitted from @motsc without explicit per-PR authorization or disclosure; withdrawn so an independent maintainer can review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants