Repository navigation
Decode the ORC byte and boolean run-length streams in bulk - #130200
Conversation
The native ORC reader decoded the boolean run-length streams one value at a time: `BooleanRleDecoder::next` refilled its byte with a one-byte `ByteRleDecoder::next` call (and a one-byte `readBytes`/`memcpy` for literal runs) every 8 values and kept its bit state in members stored through `char *`. The PRESENT stream of every nullable column goes through it, as does the DATA stream of `Bool` columns. `ByteRleDecoder::next` with a null mask (`Nullable(Int8)`, union tags) branched per position and called `readByte` per value. Both functions are the hot leaves of `formats_columns_nullable` query ClickHouse#28 (`sum(if(col_int8 IS NULL, 1, 0))` over ORC) and are where the slow aarch64 builds lose 40% on it in the performance comparison (`BooleanRleDecoder::next` x1.5-2.7 samples in 9 of 9 slow jobs). Now the unmasked boolean path decodes whole bytes with one `ByteRleDecoder::next` call per 1 KiB and expands them with a 256-entry table, and both masked paths decode the non-null values with the unmasked path and move them to their rows from the back, like `FloatingColumnReader`. The stream consumption and the decoder state between calls are unchanged. x86, RelWithDebInfo, max_threads = 1, 8 interleaved rounds of 20 runs, mean of paired ratios (95% CI): - ClickHouse#28 sum(if(col_int8 IS NULL)): 7.60 -> 3.90 ms, -48.8% (-49.7 .. -48.0) - ClickHouse#4 SELECT *: 368.5 -> 309.9 ms, -16.2% - ClickHouse#20 avg(col_int32): 8.10 -> 5.75 ms, -29.5% - ClickHouse#36 groupArray(col_string): -9.2%; ClickHouse#60 toYear(col_datetime): -7.7% - 10M rows sum(Bool): 16.85 -> 3.85 ms, -77.2% - 10M rows countIf(Nullable(Bool) IS NULL): 45.95 -> 23.00 ms, -49.9% ClickHouse#28: 44.6 -> 12.2 instructions per row, 12.3 -> 5.0 cycles per row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The seek arm compared results only, so if filter push-down stopped skipping row groups it would silently become a full read and still pass. `count()` with `indexHint(id >= 12345)` keeps all rows of the kept row groups: 18011 with push-down (row groups 0..11 skipped), 30011 without. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (Gate B) - 2 rounds, 1 finding, adjudicated
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261108-170200 |
|
Workflow [PR], commit [f3685d0] Summary: ✅
AI ReviewSummaryThe PR decodes ORC byte and boolean streams in bulk while preserving null placement and decoder state between calls. No actionable findings remain at Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
cc @alexey-milovidov @Avogar, could you review this and add the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
The flaky check runs the test with the thread fuzzer, which makes every batch of the reader expensive. On `amd_binary`, `amd_debug` and `amd_asan_ubsan` the test took 370-502 s (`Test runs too long (> 180s)`), 374-493 s of it in the reads of all 30011 rows with batch sizes 1, 3, 8, 13 and 1000. Locally with a debug build the batch size 1 read alone took 1201 s. Now everything runs in one clickhouse-local, and the small batch sizes 3, 8 and 13 read only the row groups 12 and 13 (2000 rows) through the filter push-down. Batch size 1 is dropped: 3 is coprime with 8, so it already starts and ends calls at every bit offset, and batch size 1 never reaches the bulk decoding path. The whole-file reads with 1000 and 100000 rows per batch, the seek arm and the null counts are unchanged. Measured with the thread fuzzer settings of the flaky check (debug build, this box): 8 parallel runs 91-97 s each, previously 1201 s for the batch size 1 read alone; ASan single run 82 s. The three mutation arms of the test (bit order reversed, tail forgets the partial byte, masked byte decoder without the move) still fail it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - c9ed2a0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261109-020005 |
The boolean RLE decoder expanded each byte to eight rows with a 2 KB lookup table. Spread the bits with shifts and masks instead, as the Parquet and Arrow IPC readers do, and byteswap on little-endian hosts because ORC stores the most significant bit first. clang-22 vectorizes the loop on both release targets: - x86-64-v3: 4 bytes (32 rows) per iteration in ymm registers, the byteswap becomes vpshufb, no table loads. - armv8.2-a+simd: 16 bytes (128 rows) per iteration, but the `x | (x << 7)` step is done in general registers (32 fmov/mov between NEON and GPRs per iteration). In isolation the loop is slower than the table (x86 0.036 vs 0.022 ns/row measured; llvm-mca for Neoverse N1/V1/V2 gives about 2.2x the cycles per row), but end to end the x86 release A/B against the table version shows no regression: formats_columns_nullable ClickHouse#28 4.30 -> 4.00 ms, avg(col_int32) 6.28 -> 5.97 ms, the other ORC queries within noise. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #127690
Related: #129345
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Faster reading of nullable,
BoolandInt8columns from ORC files: their run-length encoded streams are now decoded in bulk instead of one value at a time.Description
The native ORC reader decodes booleans one value at a time:
BooleanRleDecoder::nextfetches each byte with a one-byteByteRleDecoder::nextcall, andByteRleDecoder::nextwith a null mask branches and callsreadByteper value. ThePRESENTstream of every nullable column,Booldata andNullable(Int8)data go through them. They are the hot leaves offormats_columns_nullable#28 (sum(if(col_int8 IS NULL, 1, 0))over ORC), which the arm performance comparison flags as a confirmed +40-47% regression on unrelated PRs (example job); in the CPU profiles of 9 such jobs the slow side spends 1.5-2.7x more samples inBooleanRleDecoder::next.Now the boolean decoder decodes whole bytes in one call and spreads each to eight rows with shifts and masks, as the Parquet and Arrow IPC readers do (byteswapped: ORC stores the most significant bit first), and the masked paths of both decoders decode the non-null values without a mask and move them to their rows from the back, as
FloatingColumnReaderdoes since #129345. The stream consumption and the decoder state between calls do not change.x86,
max_threads = 1, this PR vs master, 8 interleaved rounds (95% CI within 2%): #28 -49% (44.6 -> 12.2 instructions per row),SELECT *-16%,avg(col_int32)-30%,sumover 10MBool-77%,countIf(nb IS NULL)over 10MNullable(Bool)-50%; no query is slower (measured with an earlier table-based expansion; the shift/mask one is not slower: #28 4.30 -> 4.00 ms). The arm numbers come from this PR's performance comparison.05569_orc_byte_and_boolean_rlecompares what is read back with the source forBool,Int8, theirNullableforms,Array(Nullable(Bool))andNullable(Tuple(...)), at batch sizes 3 to 100000 and after row-group seeks into a partial byte. It passes on master, and three mutations of the new loops each fail it.Workflow [PR]
Sync PR [sync-upstream/pr/130200]
Version info
26.11.1.2530-master(included in26.11and later)