Repository navigation
Conversation
Use direct SIMD mismatch masks for zero-padded `UInt8` equality and peel the first 16 bytes before the paired NEON copy loop. Preserve the existing padding, zero-length and signed comparison contracts. Port the measured two-file change to current master without unrelated SQuaLity commits. Prior measurements show about 1.1-1.4% lower aggregate real x86 method time and 8.7-9.4% lower Apple ARM copy entry time. Validation includes release, ASan/UBSan, x86 MSan, guard-page and alignment checks, long equality inputs and scoped actual-object proof checks.
|
Workflow [PR], commit [72848b6] Summary: ✅
AI ReviewSummaryAdds an x86-64 Missing context / blind spots
Final Verdict✅ Approve. No new inline findings; existing threads require no replies or resolution changes. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
…-arm-x86-2026-11-10
Replace the added `UInt8` equality intrinsics and explicit AVX-512 branch with unsigned 128-bit loads, XOR and a byte-order-aware partial-word mask. Use fixed-size `__builtin_memcpy` operations for the peeled ARM copy loop. The compiler selects instructions for the configured target. Preserve the common-prefix/zero-suffix semantics and strict 15-byte padding bounds. Release and ASan/UBSan guard/property checks pass, along with long inputs through 1 MiB and a two-byte-order mask equivalence check. The new standalone ARM copy object passes induction; equality object validation is limited by the proof decoder's unsupported `ccmp` instruction. ClickHouse#130445 (comment) https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130445&sha=4f92b4ce648af4a87e03f9f5f7bb6e84bc2e9fd5&name_0=PR ClickHouse#130445
Cover zero length, independent alignments and lengths around 16/32/48 with allocations containing exactly 15 trailing bytes. Exercise `UInt8` zero-padded equality with differing padding and zero/nonzero longer tails. Add guard pages at both edges, including unreadable zero-length pointers, and poison source padding in MSan builds. The existing `unit_tests_dbms` recursive gtest discovery includes these cases. Local release and ASan/UBSan runs pass. Throwaway wrong-bound and wrong-mask variants demonstrate that the tests detect an overread and a padding-dependent result. ClickHouse#130445 (comment) ClickHouse#130445
…-arm-x86-2026-11-10
`poisonPadding` does not modify the pointed-to bytes. The MSan API also accepts a const pointer, so use `const UInt8 *` and satisfy the `readability-non-const-parameter` check that blocked the public and sync `arm_tidy` builds. The focused tidy check reproduces the old diagnostic and passes after the repair. The MSan API syntax check and release/ASan/UBSan boundary tests pass. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130445&sha=f53c2251840f8d66151cc0c9cb1f334707abbb5a&name_0=PR&name_1=Build%20%28arm_tidy%2C%204%2F4%29 ClickHouse#130445
Algunenano
left a comment
There was a problem hiding this comment.
I tested the PR On x86 (Intel Xeon Platinum 8488C from AWS) I found no perf improvements. In fact, some microbenchmarks show it being slower. I'll share an agent analysis in a comment.
|
🕵 I measured this PR on x86 (Intel Xeon Platinum 8488C, End-to-end (CI
Why it is slower. On any nonzero XOR, the new code reloads both words as four 64-bit loads and clips them with a 128-bit shift in general-purpose registers ( Variants. I compiled each one with the
32-byte loads do not pay off. With 15 bytes of overread allowed, a 32-byte load is legal only when at least 17 bytes remain, so the code always needs a clipped 16-byte tail too. That adds branches. Widths of 64 and up gain only 0% to 3%. Recommendation. Use G for the using u8x16 = UInt8 __attribute__((ext_vector_type(16)));
using u8x8 = UInt8 __attribute__((ext_vector_type(8)));
using u16x8 = UInt16 __attribute__((ext_vector_type(8)));
using b16 = bool __attribute__((ext_vector_type(16)));
for (size_t offset = 0; offset < min_size; offset += 16)
{
u8x16 x;
u8x16 y;
__builtin_memcpy(&x, a + offset, 16);
__builtin_memcpy(&y, b + offset, 16);
auto ne = x != y;
#if defined(__aarch64__)
/// NEON has no movemask: narrow to 4 bits per byte (`shrn`).
const UInt64 mask = std::bit_cast<UInt64>(__builtin_convertvector(std::bit_cast<u16x8>(ne) >> 4, u8x8));
constexpr size_t bits_per_byte = 4;
#else
const UInt32 mask = std::bit_cast<UInt16>(__builtin_convertvector(ne, b16));
constexpr size_t bits_per_byte = 1;
#endif
if (mask)
{
if (offset + std::countr_zero(mask) / bits_per_byte < min_size)
return false;
break;
}
}
/// Then the existing zero-suffix check of the longer side.The loop compiles to exactly the expected instructions:
Do not use the generic bool-vector bitmask on NEON. On aarch64 it lowers to Bigger win in the caller. For c[i] = !((neq16(a + i * a_n, b + i * b_n) & min_mask) | (nonzero16(longest + i * long_n + min_n) & tail_mask));This gives −40% to −53% on equal values and mismatches, and −86% on a random 50/50 mix, because it removes branch mispredictions. The These rows cost only 1.5 to 2 ns (5 to 7 cycles), so small differences depend on how clang unswitches the outer row loop. The 2% to 5% numbers for G should be confirmed with a full build. I have not built ClickHouse with G or the caller change. |
|
Let's figure out why window functions are faster? maybe we can fix it in the window function code instead. |
Replace the 128-bit tail shift in `memequalSmallLikeZeroPaddedAllowOverflow15` with a byte mismatch mask, so x86 can use its normal compare/movemask loop without scalar word reloads or ordering mismatches. Express both x86 and NEON paths with compiler vector operations; add no AVX-512 intrinsics. Keep the exact padding and zero-length contracts and brace nested test loops. Release and ASan/UBSan gates pass on Apple ARM and x86-64 via Rosetta. The exact standalone ARM equality object passes bounded proofs through 64 bytes and rejects six deliberate object mutations. Native x86 timing is not part of these local correctness checks. Related: ClickHouse#130445 Review measurements: ClickHouse#130445 (comment)
…-arm-x86-2026-11-10
Keep the critical boundary test for the 15-byte padding and zero-length contracts. Remove the large alignment grids from the permanent gtests; those remain covered by the standalone validation and bounded proofs. The remaining multi-line nested loop uses explicit braces. Related: ClickHouse#130445 (comment)
Please go ahead and "figure out why window functions are faster" and please optimize for arm and amd both |
Add stored-data cases for unequal `FixedString` widths and `String` versus `FixedString`, including vector and constant inputs. Independent hash bits produce mixed matches and mismatches without timing data generation. Run with one thread to expose changes in the short comparison loops. The existing ordering and equal-width 16-byte cases do not exercise the changed zero-padded helper. The seven queries are parsed by the current `perf.py`; execution and final full-build timings remain pending CI. Related: ClickHouse#130445
PowerPC builds define `__SSE2__` for the intrinsic emulation layer. Do not select the x86 boolean-vector mask implementation solely from that macro; its vector comparison triggers `-Wdeprecated-altivec-src-compat` on PPC. Retain the existing comparison template on PowerPC. Both POWER8 and POWER9 reproduce the original diagnostic and compile with the fixed guard. ARM, SSE2 and AVX2 wrapper objects are byte-identical to the validated previous versions. No warning is suppressed. Related: ClickHouse#130445 CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130445&sha=f5439ede34c44107959c68017dfe1f3caedafbf0&name_0=PR&name_1=Build%20%28ppc64le%29
…-arm-x86-2026-11-10
|
🫧 The PowerPC build failure is fixed by @groeneai, please investigate and fix the separate client timezone race from the exact TSan report in a separate PR. Offline symbolization matched build ID The ARM |
|
Acknowledged. I'm investigating the client |
Withdraw the experimental ARM copy loop and retain the existing ARM equality implementation. The ARM copy change lacks final timing evidence, and the completed comparison has an unresolved window-query slowdown. Keep these runtime changes out of the patch rather than claiming a gain. The x86 byte-mask implementation is unchanged. Its SSE2/AVX2 wrapper objects match the previously validated objects exactly. ARM and PowerPC wrappers now match master exactly. Release/ASan/UBSan and long-input x86 checks pass, and the retained guard-page test focuses on equality. Related: ClickHouse#130445 CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130445&sha=f5439ede34c44107959c68017dfe1f3caedafbf0&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%201%2F8%29
…-arm-x86-2026-11-10
|
The separate fix for the client The server sends |
…data The server sends `TimezoneUpdate` right after the input-schema `Data` of the `input` initializer (also used by `INSERT ... RETURNING` with client data), and the protocol defines it as applying to the rows the client is about to send. `receiveSampleBlock` returned at the schema, so the update was read by `receiveLogsAndProfileEvents` only after `sendDataFromPipe` had started the parsing pipeline, and `onTimezoneUpdate` wrote `session_timezone` of `client_context` while the pipeline thread read it in `DateLUT::instance`: a data race, and, when the server's `session_timezone` differs from the client's (a profile `session_timezone` with `apply_settings_from_server = 0`), the first rows of the INSERT parsed in the client's time zone. For an INSERT whose data the server reads through `input` (an `input` SELECT or `RETURNING`), over a remote connection to a server new enough to send the update, `receiveSampleBlock` now reads on to the `TimezoneUpdate`, so it is applied on the main thread before any parsing thread exists. A server that sends it before the schema is handled by the existing case; `LocalConnection` sends no update and is excluded. Reported by La Casa Del Dolor (amd_tsan): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130445&sha=f5439ede34c44107959c68017dfe1f3caedafbf0&name_0=PR&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29 ClickHouse#130445 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=4951f241cfaff37833813a18a5544f0ab312ca64&name_0=MasterCI&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
🫧 Add an equality-only
UInt8specialization on x86-64 using compiler vectors and a byte mismatch mask. It avoids reloading and ordering mismatched bytes, and avoids the scalar 128-bit tail shifts from the previous revision. No new SIMD intrinsics or AVX-512 dispatch is added.ARM and other targets retain their existing implementations. The experimental ARM copy loop and ARM equality specialization were withdrawn because no application gain was established and the earlier ARM comparison had a confirmed window-query slowdown. The next ARM comparison is a control with no ARM runtime optimization enabled by this patch.
The seven direct equality tests at
f5439ede34cobserved x86 medians from 7.3% less time to 1.3% more. For example, unequalFixedString(12)/FixedString(13)took 42.7 → 39.6 ms, whileString/FixedString(32)took 46.8 → 47.5 ms. All seven were classified unchanged by the raw CI gate; these observations do not establish a statistically significant application-level gain. The x86 standalone wrapper remains byte-identical after narrowing the target guard. Current full-build CI is pending.Release and ASan/UBSan checks on x86-64 via Rosetta pass 112,056,399 assertions each, plus 69,120 long-input assertions through 1 MiB. The focused retained test checks exact padding, guard pages at both edges, runtime zero length and live-byte mismatches. POWER8/POWER9 cross-compiles pass; ARM/PPC wrapper objects match master byte-for-byte. No native x86 timing or full-program proof is inferred from these correctness checks.
A separate client
session_timezonerace is being investigated independently; see the PR discussion. It is outside the changed equality helper.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Optimize zero-padded
String/FixedStringequality comparisons on x86-64.Workflow [PR]
Sync PR [sync-upstream/pr/130445]