Skip to content

Remove dead string_columns code in BufferedV1 WASM UDF executor - #11

Open
bacek wants to merge 1 commit into
spr/bacek/master.remove-dead-string_columns-code-in-bufferedv1-wasm-udf-executorfrom
spr/bacek/remove-dead-string_columns-code-in-bufferedv1-wasm-udf-executor
Open

bacek wants to merge 1 commit into
spr/bacek/master.remove-dead-string_columns-code-in-bufferedv1-wasm-udf-executorfrom
spr/bacek/remove-dead-string_columns-code-in-bufferedv1-wasm-udf-executor

Conversation

@bacek

@bacek bacek commented Mar 13, 2026

Copy link
Copy Markdown
Owner

In UserDefinedWebAssemblyFunctionBufferedV1::executeOnBlock there was
a loop that collected pointers to ColumnString columns into a local
vector, but the vector was never read after the loop — making the entire
block dead code.

The loop logic was also incorrect: the else branch called
string_columns.clear(), erasing all previously collected pointers
whenever any column was not a pure string type. This appears to be an
abandoned fast-path optimization for all-string tables that was never
completed.

Remove the dead loop and the now-unused #include <Columns/ColumnString.h>.

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

commit-id:0152cb03

Created using spr 1.3.7
bacek pushed a commit that referenced this pull request May 14, 2026
`norm_distance #9` (`BFloat16 L1Distance`) regressed ~10% and `#11`
(`BFloat16 LinfDistance`) regressed ~7-12% on AMD release.

The hot loop is the auto-vectorised `states[VEC_SIZE]` accumulator in
`FunctionArrayDistance::executeWithLeftArgConst`.  At `-march=x86-64-v3`
clang collapses the 8 separate scalar accumulators into a single 256-bit
YMM register and emits `vpmovzxwd` + `vpslld 16` for the BF16->Float32
expansion (vs master's `pxor`/`punpcklwd` against XMM with two parallel
accumulators).  `perf stat` confirms the resulting code runs *fewer*
instructions (-40%) but at *much* lower IPC (3.40 -> 1.89) - the longer
per-iteration latency chain on `vaddps`/`vmaxps` is the bottleneck.

Tweaking the source - bumping `VEC_SIZE` from 8 to 16, or splitting into
two parallel `states_a`/`states_b` arrays - made things *worse* (clang
re-collapses them), so the fix is the same file-level `-march=x86-64-v2`
override already used for `arrayNorm.cpp`.

The `accumulateCombineBF16` AVX-512 specialisation for `L2Distance`/
`CosineDistance` is guarded by `__attribute__((target("...")))` and keeps
its Sapphire Rapids codegen even with the file-level flag.

Bench (Sapphire Rapids LTO, single-threaded, server-side):
  - `L1Distance(BF16)`:   master 0.239s,  PR 0.240s  (was 0.264s, +10%)
  - `LinfDistance(BF16)`: master 0.290s,  PR 0.289s  (was 0.311s, +7%)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bacek pushed a commit that referenced this pull request Nov 16, 2026
clang 23 vectorizes the row loop of `BinaryOperation::process` for `PlusImpl` and `MinusImpl` with a 256-bit
result on AArch64: interleaved `ld4`/`st4` of two rows and a `cmhi` per limb to recover the carry, instead of the
scalar `adds`/`adcs` chain that clang 22 emits. `wide_integer_add_sub` #9 and #11 are 1.48 and 1.24 times slower
on AArch64. Set `no_vectorize` for these two operations when the result is wider than 16 bytes. Other operations
on 256-bit integers, such as the bitwise ones, stay vectorized.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117346&sha=8f5f84ea035e5a7555cce45519db14963ea8fb59&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