Skip to content

Store module name in WasmFunctionDeclaration and WasmModule implementations - #3

Closed
bacek wants to merge 1 commit into
spr/master/0152cb03from
spr/master/fff0b868
Closed

bacek wants to merge 1 commit into
spr/master/0152cb03from
spr/master/fff0b868

Conversation

@bacek

@bacek bacek commented Mar 13, 2026 •

Copy link
Copy Markdown
Owner

WasmFunctionDeclaration now carries a module_name field (populated
from import or export metadata) alongside the function name, and exposes
it via getModuleName().

IWasmEngine::compileModule now accepts module_name as its first
argument. Both WasmTimeModule and WasmEdgeModule store the name and
use it when building export declarations via getExport, so exported
functions carry the owning module's name. Import declarations receive the
import module name from the runtime API (import_type.module() /
WasmEdge_ImportTypeGetModuleName). function_imports_map in
WasmTimeModule was removed; getImports now iterates
all_imports_list directly to preserve the per-import module name.

Host functions declared in makeHostFunction use "env" as their
module name. Export-only declarations (WASM memory manager, signature
checks) use "" since exports carry no import module.

Co-Authored-By: Claude Sonnet 4.6 [email protected]


Stack:


⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

…ations

`WasmFunctionDeclaration` now carries a `module_name` field (populated
from import or export metadata) alongside the function name, and exposes
it via `getModuleName()`.

`IWasmEngine::compileModule` now accepts `module_name` as its first
argument. Both `WasmTimeModule` and `WasmEdgeModule` store the name and
use it when building export declarations via `getExport`, so exported
functions carry the owning module's name. Import declarations receive the
import module name from the runtime API (`import_type.module()` /
`WasmEdge_ImportTypeGetModuleName`). `function_imports_map` in
`WasmTimeModule` was removed; `getImports` now iterates
`all_imports_list` directly to preserve the per-import module name.

Host functions declared in `makeHostFunction` use `"env"` as their
module name. Export-only declarations (WASM memory manager, signature
checks) use `""` since exports carry no import module.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

commit-id:fff0b868
@bacek bacek closed this Mar 13, 2026
bacek pushed a commit that referenced this pull request Apr 1, 2026
## #1: Cross-test ownership ratio (find_tests.py)

Replace plain `1/width` scoring with `1/(width × region_test_count)` where
`region_test_count = uniqExact(test_name)` for each region.  A region covered
by 1 test scores 1000× higher than one covered by 1000 tests, naturally
eliminating the hot-region problem without a hard cap.

## #2: Branch direction (LLVMCoverageMapping + coverage_log)

Parse `BranchRegion` (LLVM kind=4) in `readLLVMCoverageMapping`.  Format:
kind-marker → true_counter → false_counter → line/col, producing two
`CoverageRegion` entries with `is_branch=true` and `is_true_branch` set.
Added `branch_flags Array(UInt8)` to `system.coverage_log` (0=code, 1=true,
2=false).  Tests that covered both sides of a changed condition now carry that
information for smarter ranking.

## #3: Indirect call targets (coverage.h/cpp + CoverageCollection)

Read `LLVMProfileData::Values` (LLVM value profiling, kind IPVK_IndirectCallTarget)
to capture which concrete functions were called via virtual dispatch or function
pointers.  Each observation: `(caller_name_hash, caller_func_hash, callee_offset,
call_count)` where `callee_offset = callee_abs − binary_load_base` (from
`/proc/self/maps`), stable across ASLR restarts.  Flushed alongside coverage
counters into `system.coverage_indirect_calls`.  Fixes the fundamental gap where
a test covering `IStorage::read` cannot be distinguished from a test specifically
dispatching to `StorageMergeTree::read`.

## #4: XRay call-depth tracking (coverage.h/cpp + cmake/sanitize.cmake)

New CMake option `WITH_COVERAGE_XRAY=ON` enables `CLICKHOUSE_XRAY_INSTRUMENT_COVERAGE`.
At test start, activates XRay (`__xray_patch`) with a handler that maintains per-thread
relative call depth.  On first activation, builds a `(xray_function_id → profile_data_index)`
map by resolving each function via `__xray_function_address(id)` + `dladdr()` → symbol name
→ FNV64 hash → match against `LLVMProfileData::NameRef`.  This solves the PIE
`FunctionPointer=0` limitation: XRay provides real runtime text addresses where
`LLVMProfileData::FunctionPointer` is always null.  When enabled, `min_depth` in
`CovCounter` contains actual call depth; otherwise falls back to call-count proxy.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
bacek pushed a commit that referenced this pull request May 21, 2026
…ax indices

Address PR ClickHouse#101170 review feedback (CI #2):

- Drop the 5 add_minmax_index_for_* members from ProjectionDescription. They
  were stale ad-hoc fields duplicating MergeTreeSettings; with the new generic
  SettingsChanges flow the effective MergeTreeSettings is already the canonical
  representation.
- Thread the already-computed effective MergeTreeSettings (defaults from the
  projection index plus user WITH SETTINGS overrides) into fillProjectionDescription
  and fillProjectionDescriptionByQuery as a new parameter, instead of
  reconstructing it. fillProjectionDescriptionByQuery reads the implicit-minmax
  flags via strongly-typed MergeTreeSetting accessors.
- Add the 5 add_minmax_index_for_* names to ALLOWED_PROJECTION_SETTINGS so the
  feature added in ClickHouse#105137 (Enable Implicit Skip Indices for Projections) keeps
  working under the new settings flow.

The ATTACH validation gap raised by review item #3 is intentionally left as
`mode <= LoadingStrictnessLevel::CREATE` to match the project-wide convention
(InterpreterCreateQuery, registerStorageMergeTree, etc. all validate user input
on CREATE/SECONDARY_CREATE only). The previous loadSettings validated
unconditionally because it had no access to mode; now that we do, aligning with
the rest of the codebase is the consistent choice.
bacek pushed a commit that referenced this pull request May 26, 2026
The point-lookup queries (#4-#7) in apply_patch_parts_join produced
18-30% test noise because the four UPDATE statements that build the
patch parts ran with default parallelism. Parallel threads racing into
the patch builder produce different patch-part split boundaries on
every run, which changes how many patch granules a point lookup at
id=5000000 ends up reading. Per-server timing then depends on the
random split, not on the code being measured.

Force INSERT and UPDATE to use a single thread plus a block size large
enough to fit each whole patch, so the patch-part layout is the same
on every run. Locally verified deterministic over 20 cycles. Setup
time goes from ~4.2s to ~6.3s. Scan queries (#0-#3) still detect
patch-apply-path regressions as before.

Refs ClickHouse#100759.
bacek pushed a commit that referenced this pull request Jun 10, 2026
ClickHouse#106278 tried to remove the LIMIT-without-ORDER-BY non-determinism by
sampling with WHERE cityHash64(WatchID) % N = 0. Post-merge master data
showed it did not work: it made the measured queries scan the whole table on
every run, so instead of reducing the noise it regressed it badly:

  classification #0: 6.5% -> 76% noisy
  classification #1:  10% -> 90% noisy

(#2/#3/#4 were already clean.)

Materialize the deterministic subset once into its own single-part table
(single-threaded insert + OPTIMIZE FINAL) and measure over that, so the
determinism lives in the setup (like ClickHouse#106249 for reading_from_file) and the
measured queries read only the subset instead of rescanning the source.
alexey-milovidov pushed a commit that referenced this pull request Aug 3, 2026
Fix build: store StorageMetadataHandle in a local before conversion
bacek pushed a commit that referenced this pull request Aug 21, 2026
A query flagged in `report.html` was dropped when `all-query-metrics.tsv` had
no `client_time` row for it, and a shard whose TSV could not be read dropped
all of its flagged queries. With every flagged query dropped the run ended with
"the comparison ran and was clean" - a non-empty CI report turned into an
all-clear. The cause is deliberate on CI's side: `compare.sh` retracts a query
from the TSV when its confirmation rerun demoted it, while the report still
lists it under both "Changes in Performance" and "Unconfirmed Changes". On
PR ClickHouse#115255 that is `round_down` #2 and #3 and `and_compare_chain_derived` #2.

Those rows carry their own numbers, so they are now read from `report.html` and
marked `*` in the report - CI's verdict on them was already in doubt, which
makes them the most interesting queries to rerun, not the ones to discard. A
flagged query readable from neither source is reported as unresolved, and if
that leaves nothing to rerun the run fails instead of reporting a clean
comparison.

The commit under test drove only the report and binary lookup; the XMLs,
`perf.py`, its `stat_threshold`, and the configs still came from the working
tree. Query indices are positional and substitutions expand them, so a tree
that differs from the measured commit silently reruns a different query - on a
checkout one commit behind master, `and_compare_chain_derived.xml` has no query
#2 at all while CI flagged exactly that, and a `refs/pull/<n>/merge` checkout
is never the commit CI measured. `tests/performance`, `programs/server` and
`tests/config/top_level_domains` are now extracted from that commit into the
work dir and everything runs from there, fetching the commit when the clone
lacks it. `--use-working-tree-tests` opts out for iterating on a local test.

Verified: all six flagged queries of PR ClickHouse#115255 are now kept, the three the TSV
retracts carrying the report's numbers and flagged as unconfirmed; a dry run of
PR ClickHouse#112688 recovers `date_time_64` #5, which had been dropped the same way, and
runs against the extracted tree.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115278&sha=baefff6dcc4dbb3201337a52b5ca54453fb34562&name_0=PR&name_1=Style%20check
Pull request: ClickHouse#115278

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GYYbBbrQpmi2zkYJ8LQw5Z
bacek pushed a commit that referenced this pull request Oct 3, 2026
…nce per block

`mortonEncode` with two arguments ran one row loop for every argument type
and mask: per row and argument it tested the mask and `is_const`, reloaded
the ratio, switched on the column width and, with a mask, called the
out-of-line `expand` (36 call sites in the arm `executeImpl`). On arm the
speed of the branch-dense paths depends on the binary's layout, so
`space_filling_curve` #1 (constant mask) and #4 (`UInt32` arguments) have
per-build speed modes and flag unrelated PRs in Performance Comparison
(ClickHouse#122482), while #2 (two `UInt64` columns) is stable.

Now each argument is resolved once per call into a contiguous `UInt64` array
with the range expansion applied: a `UInt64` column that needs no expansion
is read in place, other widths are widened with one type dispatch, and a
constant ratio is applied in one loop per ratio value (`expand` is
`ALWAYS_INLINE` and called with a template-constant ratio, so its switch
folds). A per-row mask keeps the per-row `expand`. `nd == 1` writes the
result column directly. The encode loops only encode.

x86, one core, median fix/base of 5 interleaved rounds over the queries of
`space_filling_curve.xml`: #1 0.57 (BMI2) / 0.55 (lookup-table path, built
with `-mno-bmi2`), #2/#3/#6 0.45-0.64, #4 0.86-0.88, untouched functions
0.99-1.03. Results are unchanged: 545 checksums over every width, mask and
ratio are byte-identical before and after on both code paths, and the new
test fails on both paths under two mutations of the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bacek pushed a commit that referenced this pull request Oct 3, 2026
…test

The two compared servers each built a different copy of the fixture:

- `rand64() % 5000000` makes the number of rows with key 5, which queries
  #1 and #3 look up, a fresh draw per server (0 to 3 over 10 local fills);
- each INSERT is squashed into ~5 parts (cut at min_insert_block_size_rows),
  which merge until perf.py's --stop-merges freezes them at a per-server
  point.

#1 and #3 read about one granule per part, so each server read its own
number of granules: in CI the servers read different parts in 80% of runs,
and time follows the rows read (correlation 0.85-0.88). This redded
unrelated PRs (e.g. ClickHouse#118662, arm 4/6, #1 +37.5% confirmed_regression) and
inflated the learned threshold of #1/#3 to 0.41-0.53 (0.04-0.09 for
#0/#2/#4 on the same tables); the dashboard now caps both at
likely_regression as "Flaky lately", so a real regression there cannot red.

Use deterministic data, cityHash64(number, 7) and cityHash64(number, 11)
modulo 5000000 (same key range and duplicate profile; the seeds put key 5
once in each table, the modal case of the random draw, so #1/#3 keep
measuring a non-empty point join), and write each table as one part with
min_insert_block_size_rows = 10000000, min_insert_block_size_bytes = 0
(5M rows give one squashed block). A throwIf on system.parts fails the
fill if the layout ever drifts. Same shape as ClickHouse#122479 and ClickHouse#122660.

Validated through perf.py --stop-merges on two servers, 5 fresh fills per
arm: new fixture identical on all 10 server fills (one part per table, same
data, #1/#3 read 2 granules on both, #0/#2/#4 read 10M rows); old fixture
different on all 5 iterations. Without the insert settings the throwIf
fails the fill.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bacek pushed a commit that referenced this pull request Oct 17, 2026
The scaled loop of `convertToDecimalBatch` checked every row twice: the
multiplication against `DecimalScaleBounds` of the wide intermediate type, then
the product against the destination range. A cast from `Int128` paid four
`Int256` comparisons and an `Int256` multiplication per row, which made
`decimal_casts` #3-#6 1.15-1.74x slower than master (Performance Comparison,
arm_release).

The source values whose product with `m` fits the destination are
`[ceil(min / m), floor(max / m)]`. Compute that range once per block, clamped to
the source type, compare each row in the source type and multiply in the
destination type. A `UInt256` above the `Int256` maximum is above that range, so
it needs no separate check in this loop.

The results are the same as before for every integer source type, decimal width
and scale (boundary values around both limits checked against an independent
oracle). On an x86-64-v3 RelWithDebInfo build the casts take 0.39-1.03x of
master's time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit that referenced this pull request Oct 19, 2026
…efore measuring

Since 2f07f3f (ClickHouse#122231) `t_materialize_uniq_v2_{i64,f64}` no longer stop
merges, so background merges run while the fill commits its 20 1M-row parts
and keep running during queries #0-#3. Each compared server ends up with its
own layout (CI server logs: 8 servers, 8 layouts, from [6,6,6,1,1] to [20]
million rows). The measured `ALTER ... CLEAR STATISTICS ALL, MATERIALIZE
STATISTICS ALL` runs one single-threaded mutation task per part, so its time
follows the largest part, and the layout lasts the whole job, so the dashboard
confirmation restart reproduces the gap (`confirmed_regression` on unrelated
PRs, e.g. ClickHouse#126296: #4 0.1445 -> 0.1933 s).

Merge both tables into one part in the fill with `OPTIMIZE TABLE ... FINAL
SETTINGS optimize_throw_if_noop = 1` and assert one active part per table with
`throwIf`, as `and_compare_chain_derived.xml` does. Without
`optimize_throw_if_noop` a failed merge assignment only logs and returns
success, leaving a random layout. A table that background merges already
collapsed to one part is still rewritten under FINAL, so the pin never throws
on it. `projection_materialize.xml` measures a mutation over one merged part
the same way and is stable on the same harness.

Validated on the official master release build (26.11.1.120): before, 10
fills gave 5 i64 layouts and a 1.92x spread of #4, and perf.py on two servers
gave right/left 1.249, 0.892, 0.841 in 3 of 5 fills; after, one 20M-row part
per table in 10 of 10 fills, #4/#5 spread 1.029/1.041, and perf.py right/left
within 5% in 5 of 5. Replacing one OPTIMIZE with `SELECT 1` fails the fill.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bacek pushed a commit that referenced this pull request Oct 23, 2026
…h set

When `hasAny(Array(String), <constant Array(String)>)` does not build the
needle hash set for a block (fewer than 4 needles, a needle longer than 256
bytes, or a block too small for the set to pay off), it used to fall back to
the generic GatherUtils path. That path makes two virtual calls per row from
the per-row loop of `arrayAllAny` (`ColumnString::structureEquals` from
`sliceHas`, and `ColumnString::compareAt` per element/needle pair).

The speed of that loop turned out to depend on code placement. Three PR builds
of 2026-10-18 (ClickHouse#123788, ClickHouse#100394, ClickHouse#63383; their diffs share no file and none
touches Functions/ or Columns/) ran `has_any_constant_string_needles` queries
#5 and #6 1.2-2.1x slower than the master reference in all three process
lifetimes of their perf job, on three different runners, with md5-identical
machine code for the four functions involved. Across 24 inspected CI builds, a
build is slow exactly when a 64-byte line of `compareAt` or `structureEquals`
coincides with a line of the `arrayAllAny` loop modulo 8 KiB (3/3 slow, 0/21
fast). Reproduced locally with the CI binaries: query #6 takes 1.04-1.35 s on
the three slow builds vs 0.62 s on three fast ones, at equal instruction counts.

Now the declined block compares each element with each needle directly
(`getDataAt` + `memequalSmallAllowOverflow15`, the comparison
`ColumnString::compareAt` makes), in the generic path's order (needles outer,
elements inner, first match wins). The loop has no call left, and it is faster
for every declined shape: on a release build, perf test queries #4-#7 take
0.73-0.91x of the base time and #0-#3 (set path) are unchanged.

Adds perf query #7 for the fewer-than-4-needles branch, the only declined
branch the test did not cover. Non-String columns still use the generic path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bacek pushed a commit that referenced this pull request Nov 14, 2026
…up window

`NegativeLimitBySortedStreamTransform::consume` sent every group, even one
that starts and ends inside the current chunk, through the sliding window:
`append_run` pushed a `ChunkSlice` into the empty window deque (allocating the
deque map and a block, and copying the chunk `shared_ptr`), `finalizeWindow`
copied it into `pending` (a second `shared_ptr` copy) and then `window = {}`
(libc++: `clear(); shrink_to_fit();`) freed the block and the map. So each
one-row group cost two memory-tracked allocations, two frees and two atomic
increment/decrement pairs, plus one `pending` entry.

The window is only needed for a group that touches a chunk boundary. A group
that ends inside the chunk while the window is empty also started inside this
chunk, so its output is known when its end is found: the last
`min(L, length + offset)` rows of the run without the trailing `offset` rows,
the same rows `append_run` + `dropExcessRows` + `dropOffsetRows` keep for a
one-slice window. Such groups are now staged into `pending` directly, and
`appendToPending` extends the last pending slice when the new rows continue
it in the same chunk, so the one-row groups of a chunk become one slice.
`generate()` produces the same chunk for a merged slice (same rows, first
start and last end). Groups touching a chunk boundary still use the window.

Evidence that this path is what moves the `negative_limit_by_in_order`
queries #0, #1 and #8 (millions of groups): ClickHouse#125000, which changed only the
allocator of these deques, moved them by -19/-16/-17% on master d3ee313 while
#2-#7 stayed flat; and the ClickHouse#125013 perf job's prewarm counters for #0 show
equal instructions on both sides (10301M vs 10333M, ~1030 per group) and +15%
cycles on one build.

Local A/B (release build, `CMAKE_BUILD_TYPE=None`, no ThinLTO, the perf
test's tables and queries, 12 rotating rounds, geomean of per-round ratios
new/base with bootstrap 95% CI):

  #0 10M one-row groups      0.764 s -> 0.096 s  0.123 [0.113, 0.135]
  #1 1M groups of 10         0.098 s -> 0.049 s  0.457 [0.413, 0.510]
  #2 100k groups of 100      0.025 s -> 0.019 s  0.707 [0.642, 0.785]
  #3-#7 100 groups           0.86-1.03, no CI lower bound above 1.0 (4-15 ms)
  #8 5M two-key groups       0.447 s -> 0.116 s  0.250 [0.236, 0.265]

User-space instructions of 5 runs of #0: 60.3G -> 10.2G (~1190 -> ~190 per
group after subtracting 5 runs of #3), cycles 16.2G -> 3.1G; #8: 31.4G ->
6.4G instructions. In the base profile of #0 about half of the samples are
in the deque allocation, `shrink_to_fit`, `CurrentMemoryTracker` and
jemalloc; none of them is in the top 15 after the change.

Replacing only `window = {}` by `clear()` (keeps the deque blocks) gives
0.526 / 0.594 / 0.583 on #0 / #1 / #8, so the direct staging is 4.3x and
2.3x faster than that on #0 and #8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bacek pushed a commit that referenced this pull request Nov 16, 2026
filterWithBlanks copied the left key into the right key column of a LEFT JOIN
one row at a time, with a virtual insertFrom or insertDefault per row. It now
reads the filter 64 rows at a time (bytes64MaskToBits64Mask, as in
filterArraysImpl): a chunk whose rows are all kept is one insertRangeFrom, a
chunk whose rows are all blank is one insertManyDefaults, and any other chunk
keeps the per-row loop. ColumnNullable gets an insertManyDefaults override, so
a blank Nullable chunk fills the nested column and the null map in bulk instead
of 64 virtual insertDefault calls.

Measured on x86 release (8 pinned cores; wall = median of 21 runs, user-space
instructions = median of 3 perf stat runs minus startup), base -> this commit:
- join_nullable_keys_small_table #4: 0.61x wall, 0.47x instructions;
  #8: 0.71x / 0.55x; #3: 0.66x / 0.55x; #7: 0.80x / 0.66x.
- Alternating rows and runs of 2, 3 and 100 rows: 0.86x-0.99x instructions.
- Queries of the same test that do not reach filterWithBlanks: within 0.4%
  instructions (wall moves up to +23% between the two builds from code
  placement alone, with the same instruction count).

The added perf query covers the per-row path (alternating matched and
unmatched rows), which the existing queries of the test do not reach.
The test runs all its queries (`run_all_queries`), as it now has more than
the 10 that CI samples.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bacek pushed a commit that referenced this pull request Nov 16, 2026
…oop over batches of rows

The previous commit replaced the per-row `isCancelled` load with a mask
test on the row index. On AArch64 clang-23 keeps that test and its branch
in the row loop (`tst x23, #0x3ff; b.ne` per row, the only difference
from the previous build of this branch), and `limit_by` #0/#3/#5/#6 and
`optimize_limit_by_keys` #0/#1 are 1.18-1.22x slower than master there,
while the two previous runs had them at 1.00x.

Make the batching explicit instead: an outer loop over batches of 1024
rows checks for cancellation, and the inner row loop contains the hash
lookup only. Measured with the CI binaries on a Graviton 4 host against
the clang-22 master build: 0.99-1.05x (PR build: 1.18-1.22x).

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117346&sha=d847a368b13c19355fbfac4bbcec67663d20ec9f&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%201%2F6%29
PR: ClickHouse#117346

Co-Authored-By: Claude Fable 5.1 <[email protected]>
bacek pushed a commit that referenced this pull request Nov 16, 2026
…ch64

`avg` #3 (`avgIf` over `UInt8`) is 1.18x slower on ARM with clang 23, all
of it in `AggregateFunctionSumData<UInt64>::addManyConditionalInternalImpl<char8_t>`.
clang 22 vectorizes that loop as a partial reduction (`udot` into 32-bit
lanes, then `uaddw` into the 64-bit accumulator); clang 23 widens every byte
to 64 bits with `tbl` and needs twice the instructions. The cause is the
AArch64 partial reduction cost model rewrite in LLVM 23
(llvm/llvm-project#181707), which prices 8-to-64-bit
partial reductions for NEON as a full expansion, so the loop vectorizer no
longer picks them. It is fixed on LLVM `main` only
(llvm/llvm-project#226226). The same applies to the
plain `addManyImpl` and to 16-bit inputs.

Sum into a `UInt32`/`Int32` over chunks short enough not to overflow it and
add each chunk to the 64-bit sum. Every compiler vectorizes that with
`udot`/`sdot`; a standalone copy of the loop runs at 0.026 ns/row with both
clang 22 and clang 23, against 0.045 (clang 22) and 0.090 (clang 23) before.
The result is the same because chunk sums cannot overflow.

ClickHouse#117346

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bacek pushed a commit that referenced this pull request Nov 16, 2026
…registers

After the outer batch loop of c23127a, clang 23 on AArch64 keeps two values
in `consumeImpl` that depend on the current row's hash table load in callee-saved
registers. The out-of-line `processRunInsideWindow` saves and restores them in
`stp`/`ldp` pairs together with registers on the next row's key load path, so the
next lookup waits for the previous row's cache miss: `limit_by_in_pk_order` #3
+80%, `limit_by_with_order` #1 +77%, `limit_by` #1 +42% on ARM, with user time
x1.91 and the same page faults. This is the mechanism of e16e062, one call
level down.

Move the growth of `output_slices` into a separate function reached by a tail
call, so `processRunInsideWindow` makes no calls and saves only `x29`/`x30`
(checked in an AArch64 ThinLTO build of the translation unit with clang 23.1.4;
on x86 it saves nothing either).

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117346&sha=8675465598566b9a2f459432b9831f33b2876b86&name_0=PR
PR: ClickHouse#117346

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bacek pushed a commit that referenced this pull request Nov 16, 2026
The collation sort (#2, 5M rows) and the single-column string sort (#3,
20M rows) take 1.2-1.9 s on MasterCI on both arches. They get
disabled="1" (text and number unchanged) and are appended as #9 and #10
on a quarter of the rows with max_block_size = 16384, a quarter of the
default 65409. `numbers_mt` hands out blocks of exactly max_block_size
rows, so each copy has as many blocks as its original (77 and 306): the
same number of cursors in every per-stream merge and the same 16-stream
final merge, with a quarter of the rows per block. EXPLAIN PIPELINE of
each original and its copy is identical (16 streams).

Measured on official MasterCI release builds, two servers pinned to 24
cores of one NUMA node, perf.py, 25 runs: copy / original time 0.248
(#2) and 0.252 (#3), projected CI medians 380 / 487 ms amd, 298 / 483 ms
arm. On the builds before/after ClickHouse#115869 (sorted array of cursors) #2 is
1.161x faster and its copy 1.159x; on those before/after ClickHouse#126829
(cheaper collation) 2.179x and 2.111x; #3 and its copy show no change
on either pair (1.005 / 1.008, 1.004 / 1.001), as the heap guard should.

#0 and #1 stay as they are: on this rig the ClickHouse#115869 change did not show
on them beyond the A/A resolution, so there was no measured guarantee
that copies would keep their sensitivity.

About 32 s (amd) and 29 s (arm) of query time less per master
performance job; 9 queries stay enabled, so all of them still run.

Related: ClickHouse#129258

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant