Repository navigation
Decode the offsets of a sparse column from a local pointer - #129768
Conversation
deserializeOffsets read every VarUInt of the offsets stream through readVarUInt(UInt64 &, ReadBuffer &), so the inlined loop stored the buffer position after every byte, reloaded the position and the buffer end for every VarUInt, and reloaded offsets.back() for every value. Decode from a local pointer while a whole VarUInt is in the buffer, write the position back only when leaving that path, and carry the row of the next value in a local. The last bytes of a buffer are still read through the ReadBuffer, because a VarUInt there can continue in the next one. 04147_sparse_column_coverage now also reads sparse columns written in 13-byte compressed blocks, so their VarUInts are split between buffers, with reads that stop in the middle of a group. Idea and analysis by snelheidai in ClickHouse#129686. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add in-granule gaps of 128+ rows to both sparse columns so their offsets streams also hold 2-byte VarUInts split between 13-byte blocks, and pin index_granularity_bytes so granules stay at 1000 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the add_group and fast-path comments to one line each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
cc @Avogar, could you review this and add the Pre-PR validation gate (click to expand)
|
|
Workflow [PR], commit [dd102b0] Summary: ✅
AI ReviewSummaryThis PR speeds up sparse-column offset decoding in Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; CI validation remains pending. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 7 s compile time in total, 8 of them have a recent master baseline. |
Algunenano
left a comment
There was a problem hiding this comment.
Nice improvement on top of 269567a
98d000d

Related: #129686
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reading sparse columns is faster: the offsets of their non-default values are decoded from a local pointer instead of updating the read buffer position for every byte.
Description
deserializeOffsetsreads one VarUInt per non-default value, and one per granule, throughreadVarUInt(UInt64 &, ReadBuffer &). In the ThinLTO binary the inlined loop stores the buffer position after every byte, reloads the position and the buffer end for every VarUInt, and reloadsoffsets.back()for every value.Now, while a whole VarUInt (10 bytes) is in the buffer, it is decoded from a local pointer, the position is written back only when leaving that loop, and the row of the next value is kept in a local. The last bytes of a buffer are still read through the
ReadBuffer, because a VarUInt there can continue in the next one. The disassembly shows no store to the buffer in the new loop.Measured, master
35fed92ffa43vs this PR (Xeon 6975P-C, 16 pinned cores, ThinLTO clang-22; two perf.py runs; ClickBench with 95% CI):sparse_column_filtersum(u64) ... PREWHERE u8 = 0at 10% non-default, 1 thread: -11.2% / -12.9%.sparse_column_index_sortedsum(b) ... WHERE a != 0: -5.4% / -5.4%.max_threads = 1:WHERE MobilePhoneModel <> '' GROUP BY MobilePhoneModel-4.5% [-6.3, -2.8],GROUP BY MobilePhoneModel-2.6% [-3.6, -1.5], the sameWHEREwithGROUP BY MobilePhoneModel, UTMSource-2.9% [-5.5, -0.3]. At 16 threads: within noise. Controls (AVG(UserID),SearchPhrase) unchanged, results identical.This is the form proposed in the issue.
Stringsizes are read the same way; they are not changed here.04147_sparse_column_coveragenow also reads sparse columns written in 13-byte compressed blocks, so VarUInts are split between buffers, withmax_block_size7, 1000 and random; mutants of the new loop (bounds, row arithmetic, position stores) fail it. The*sparse*stateless tests match master.Idea and analysis by snelheidai in #129686.
Workflow [PR]
Sync PR [sync-upstream/pr/129768]
Version info
26.11.1.1980-master(included in26.11and later)