Skip to content

Wire minimal WASI to WasmTimeRuntime. - #5

Closed
bacek wants to merge 1 commit into
spr/master/9883fc0ffrom
spr/master/47342619
Closed

bacek wants to merge 1 commit into
spr/master/9883fc0ffrom
spr/master/47342619

Conversation

@bacek

@bacek bacek commented Mar 13, 2026 •

Copy link
Copy Markdown
Owner

It will allow to use WASI provided functions, but it's pretty limited at
the moment.

Next steps are:
* Wire stdout/log/err to some internal logging mechanism.
* Configure directory access.

commit-id:47342619
@bacek bacek closed this Mar 13, 2026
bacek pushed a commit that referenced this pull request May 14, 2026
…ressions

`general_purpose_hashes ClickHouse#48` (`xxh3(materialize(''))`, 10M rows) regressed
~21% and `general_purpose_hashes #5` (`farmHash64(materialize(''))`, 500M_mt)
regressed ~11% on AMD release.

`xxh3`'s empty-string fast path is a tiny `movabs rax, const; ret` block
reached via three forward branches.  At `-march=x86-64-v3`, BMI2 encodings
(`mulx`, `rorx`) used in the *medium-input* path of the inlined XXH3 body
are 1-2 bytes longer than v2's `mul`/`shld`, shifting the entire function
layout.  This pushes the empty-string `movabs` to start at byte 31 of a
16-byte IFU fetch window (vs byte 16 in v2), splitting one fetch into two
on every call.

Reproduced with a standalone microbenchmark calling `XXH_INLINE_XXH3_64bits`
in a tight loop: v2 1.6 ns/call vs v3 2.2 ns/call (+38%).  IPC drops from
2.79 to 2.00 with the same instruction count, consistent with front-end
fetch stalls rather than back-end pressure.  Disabling BMI2/AVX2 individually
does not restore master timings — only forcing v2 codegen does.

Compiling `FunctionsHashingMisc.cpp` at v2 (which holds the dispatchers for
sipHash, cityHash, farmHash, metroHash, javaHash, hiveHash, xxHash, xxh3)
restores master timings.  Locally on Sapphire Rapids (non-LTO):
- `xxh3(materialize(''))` 10M:      master 0.028s, PR-fixed 0.027s
- `farmHash64(materialize(''))` 500M_mt: master 0.336s, PR-fixed 0.314s

The AVX2 hash kernels are inline in their respective contrib headers and
remain at v3 in TUs that use them with non-trivial input.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bacek pushed a commit that referenced this pull request May 14, 2026
…tion` regressions

`generate_table_function #1` (8 integer column types, 1B rows) regresses ~18% and `#5`
(Date/DateTime, 1B rows) regresses ~16% on AMD release.

`fillColumnWithRandomData` is a big switch over `TypeIndex` that constructs a fresh
column for every block.  At `-march=x86-64-v3` the SLP vectorizer lowers the implicit
~32-byte zero-init of each newly-allocated `ColumnVector`/`ColumnString` to a
`vpxor xmm0; vmovdqu ymm0` pair (29 occurrences in PR vs 0 in master).  Each YMM
store dirties the upper YMM state, so clang inserts a `vzeroupper` (30 inserted)
before every external call from the dispatcher (`operator new`,
`PODArrayBase::reallocPowerOfTwoElements`, etc.) - the per-block dispatch ends up
bracketed by ~30 SSE/AVX transitions for no benefit (the inner PCG generation loop
is byte-equivalent to master's).

The inlined PCG inner loop is the dominant per-row cost, but at v3 the broader
function bloats from 16654 to 18241 bytes (+10%) and the cumulative `vzeroupper`
overhead in the per-block dispatch is what surfaces as the +15-18% regression.
The integer/Date paths are uniformly affected; Decimal/Float paths (#7/#8/#9)
do not regress because they go through a different per-element loop with no YMM
zero-init.

Compiling at v2 keeps the XMM-only zero-init that does not require `vzeroupper`.
The hot PCG inner loop's quality is not affected (master is already at v2 and
generates the same scalar code).

Local Sapphire Rapids LTO (max_threads=12, 10 iter):
  - `#1`:                      master 0.521s, PR 0.521s  (was 0.614s, +18%)
  - `#5`:                      master 0.177s, PR 0.178s  (was 0.208s, +16%)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bacek pushed a commit that referenced this pull request May 14, 2026
Commit 7bb9509 ("Remove unnecessary dispatch") removed the
`x86_64_v3` specialization on the assumption that at a v3 build the
`Default` namespace is already v3, making the per-function attribute
redundant.

That assumption breaks for files compiled with explicit `-march=x86-64-v2`
overrides. `FunctionsHashingMisc.cpp` is one such file (overridden to
avoid an unrelated SLP regression in `xxh3 ClickHouse#48` / `farmHash64 #5`).
Without a v3-attribute specialization there, the runtime dispatcher
falls back to the v2-compiled `Default` body, which uses SSE2/XMM
codegen instead of AVX2/YMM. That regressed `hiveHash` / `javaHash` on
UUID and Decimal128 columns by 12-18% (perf tests
`general_purpose_hashes_on_UUID ClickHouse#30` and `ClickHouse#32`, `ClickHouse#58` on Decimal).

Restore the `DECLARE_X86_64_V3_SPECIFIC_CODE` macro, the `x86_64_v3`
slot in `DECLARE_MULTITARGET_CODE`, and the per-function `x86_64_v3`
registration in both `FunctionIntHash` and `FunctionAnyHash`. This goes
hand-in-hand with the v2 override on `FunctionsHashingMisc.cpp`: that
override stays as the SLP fix, and this restoration makes the dispatcher
recover the AVX2 fast path on hosts that support it.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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 Aug 21, 2026
…nger adds

The previous commit claimed the pruning was not measurable. That was measured on the wrong shape: a
20M x 5M join where every left row matches one right row is dominated by the probe, and the columns
that go away are a small part of the work. The win scales with the number of result rows, and CI found
it on the shapes that have many - `join_nullable_keys_small_table` #5 and #9 and `join_main_loop` #8,
all of them `count()` over a join with disjuncts, went -30%, -34% and -16% on ARM.

Reproduced locally against a build of the parent commit, min of five runs, `max_threads = 8`:

  200M left rows, 1000 right, two `UInt64` keys, count only   424 -> 243 ms
  20M left rows, `String` keys                                102 ->  83 ms,  31 -> 1 MiB
  one of the two keys selected, so only the other one goes    432 -> 390 ms
  RIGHT, which also emits the non-joined right rows           134 -> 138 ms (unchanged)

The test covers those four shapes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016QJvAjMfovbKtDsMW9mDbF
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 Oct 23, 2026
…the table

Queries #5 (update_partition_key_move) and #9 (update_every_file) of
iceberg_suite_{local,s3}_rw_features are Iceberg ALTER ... UPDATEs whose
WHERE still matches after they ran: #5 re-matches the rows it moved to
partition 'X', #9 matches l_partkey % 10 = 0 forever. Iceberg UPDATE is
merge-on-read, so every execution commits another data file and
position-delete file that the next execution scans, and perf.py has no
per-run reset. Run time therefore grows monotonically within a series
(query_metric_runs_v1, master 2026-10-21: files read per run 6, 8, ..., 18
for #5 and 4, 6, ..., 16 for #9), and the comparison reported both as
unstable on 63-87% of master commits (2026-10-08..10-19, issue ClickHouse#100759).

Make the prewarm run do the one real rewrite and later runs match nothing,
as the suite already does for delete_position_deletes, modify_column and
optimize_manifests: #5 adds `AND l_returnflag != 'X'`, #9 becomes
`l_quantity + 100 ... AND l_quantity < 100` (TPC-H l_quantity is 1..50, and
the predicate stays idempotent for any non-negative value). A mutation that
matches nothing commits nothing, so the measured runs time the mutation's
planning and merge-on-read scan over a fixed table; the rewrite itself
still executes once per server.

The #9 comment no longer claims three data files: the Iceberg writer only
starts a new file at a block boundary, so the 30000-row single-block INSERT
with iceberg_insert_max_rows_in_data_file = 10000 produces one file, on CI
as well (#9 measured run0 reads 4 = 2 passes x 2 files).

Validated locally on a master build, 16 executions per variant: the old
text grows by 2 files read and 1 snapshot per execution (corr(run,
duration) 0.99 / 0.92), the new text is constant after the first measured
run (corr -0.47 / -0.45) with the expected row counts; perf.py
--print-queries shows every other query index unchanged in both suites.

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

Stop the Iceberg rw_features perf UPDATE queries #5 and #9 from growing the table on every run
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
…nHeapBase::fillSkipBitmap`

clang 23 turns `direction * CompareHelper<T>::compare(...) > 0` into a `ucmp`/`scmp` intrinsic that the x86
backend expands to a scalar `cmp`/`seta`/`sbb`/`imul` per row, where clang 22 emitted an 8-wide AVX2 compare.
`optimize_trivial_group_by_limit` #4 and #5 were 1.13-1.18x slower on x86 in the last four performance runs of
ClickHouse#117346 because of it.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117346&sha=3dd3995a5ef4e0b7c19340ffe509331cf3e91827&name_0=PR

Co-Authored-By: Claude Fable 5.2 <[email protected]>
bacek pushed a commit that referenced this pull request Nov 16, 2026
The row loop of `mortonDecode` read the code through `UIntColumnSpan::operator[]`, which dispatches on the width
of the column, reloaded the data pointers of the result columns, and tested the mask, all for every row. Run the
loop inside `UIntColumnSpan::withReader`, which passes a reader specialized for the width, and hoist the result
pointers and the mask test. `morton_decode` #0 and `space_filling_curve` #5 are 1.10 to 1.15 times slower on
x86-64 in the performance comparison of clang 23; with this change `morton_decode` is 29% to 63% faster than
before locally.

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

Co-Authored-By: Claude Fable 5.2 <[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