Skip to content

Add profile events for rows processed by compiled and interpreted functions - #128973

Draft
Manerone wants to merge 2 commits into
masterfrom
manerone-jit-function-rows-events
Draft

Manerone wants to merge 2 commits into
masterfrom
manerone-jit-function-rows-events

Conversation

@Manerone

@Manerone Manerone commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

CompiledFunctionRows counts the rows processed by JIT-compiled expressions, once per function fused into the compiled expression, so a block of N rows through a compiled plus(plus(a, multiply(b, 2)), 1) adds 3N. InterpretedFunctionRows counts the rows processed by ordinary functions that run without JIT compilation, once per function, at the same places that count FunctionExecute: normal execution in ExpressionActions, and lazy (short-circuit) execution in ColumnFunction::reduce.

Together they give the share of function evaluations that run compiled, which the existing counters FunctionExecute and CompiledFunctionExecute cannot: they count blocks, and a compiled call of ten fused functions counts the same as one interpreted plus. This is the measurement for the work on expression compilation tracked in the issue below.

Related: #126979

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added profile events CompiledFunctionRows and InterpretedFunctionRows: the number of rows processed by JIT-compiled expressions (counted once per fused function) and by functions executed without compilation, so the share of a query that runs compiled can be seen in system.query_log.


Workflow [PR]
Sync PR [sync-upstream/pr/128973]

…ctions

`CompiledFunctionRows` counts the rows processed by JIT-compiled expressions,
once per function fused into the compiled expression, so a block of N rows
through a compiled `plus(plus(a, multiply(b, 2)), 1)` adds 3N.
`InterpretedFunctionRows` counts the rows processed by ordinary functions that
run without JIT compilation, once per function, at the same places that count
`FunctionExecute` (normal execution in `ExpressionActions` and lazy,
short-circuit execution in `ColumnFunction::reduce`).

Together they give the share of function evaluations that run compiled, which
the existing block counters `FunctionExecute` and `CompiledFunctionExecute`
cannot: they count blocks, and a compiled call of ten fused functions counts
the same as one interpreted `plus`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Nov 3, 2026
Brings in #124680 and #126022, which the JIT correctness work stacked on this branch depends on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8e30ed0]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted, old_compatibility) FAIL
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-26fa) FAIL cidb
Stateless tests (amd_msan, flaky check) FAIL
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
05366_jit_function_rows_profile_events FAIL cidb
6 more test cases not shown

AI Review

Summary

Adds CompiledFunctionRows and InterpretedFunctionRows to measure the share of expression evaluations executed by JIT, including fused functions and short-circuit execution. Reviewed PR head 8e30ed0a80643fc846e5f8283d9474e80497418c and all prior discussion; there were no existing findings. Request changes because the counters use different row units for compact inputs, and the new test fails when run with MSan.

Missing context / blind spots
  • ⚠️ No local ClickHouse build or executable was available. The retrieved Praktika report contained Fast test results but no completed stateless-test results; the new test is excluded from Fast test. A completed JIT-enabled stateless run would close the runtime-validation gap. Findings below follow directly from the current execution and build paths.
Findings

⚠️ Majors

  • Inconsistent row accounting makes the advertised compiled share incorrect. src/Interpreters/ExpressionJIT.cpp:130 counts rows after IExecutableFunction applies compact-representation wrappers, whereas ExpressionActions.cpp:896 and ColumnFunction.cpp:554 count logical rows before those wrappers. For toString(x + x * 2) over one 1000-row sparse block with one nondefault value, both execution paths evaluate two stored values, but the counters record 4 compiled rows and 1000 interpreted rows: about 0.4% compiled instead of two thirds. Count both events at the same boundary and apply that rule to lazy execution as well.
  • The new test deterministically fails in MSan builds. tests/queries/0_stateless/05366_jit_function_rows_profile_events.sql:1 excludes only Fast test, but MSan also disables the embedded compiler. The first and mixed queries consequently report compiled/interpreted counts of 0/3000 and 0/4000, contradicting the reference. Add the necessary no-msan tag or conditional assertions that retain absolute validation when JIT is available.
Tests
  • ⚠️ Add a focused stateless case with a verified ColumnSparse input and a mixed compiled/interpreted expression. Assert comparable row accounting across both paths; the existing dense-input cases cannot detect the mismatch.
Final Verdict

Status: ⚠️ Request changes. Align the counter units and cover sparse inputs, then make the new test compatible with MSan and run it on a JIT-enabled build.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 5, 2026

auto jit_compiled_function = compiled_function_holder->compiled_function.compiled_function;
callJITFunction(jit_compiled_function, input_rows_count, columns.data());
ProfileEvents::increment(ProfileEvents::CompiledFunctionRows, input_rows_count * fused_functions_count);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Use the same row unit for compiled and interpreted evaluations

This increment runs after the default implementations in IExecutableFunction have reduced the input, while InterpretedFunctionRows is incremented before those wrappers in ExpressionActions and ColumnFunction::reduce. For example, consider toString(x + x * 2) on a single 1000-row ColumnSparse with one nondefault value. The sparse wrapper calls the two-function JIT on its two stored values, adding 4 compiled rows, and preserves the sparse result. The interpreted toString also evaluates only those two stored values, but its counter adds 1000. The advertised compiled share is therefore about 0.4%, although two of the three function evaluations are compiled.

Please account for both events at the same boundary, either consistently counting logical rows or consistently counting the reduced rows actually evaluated. Apply the same rule to lazy execution and add a focused sparse-input regression test; the dense numbers cases do not exercise this mismatch.

@@ -0,0 +1,30 @@
-- Tags: no-fasttest

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Handle the missing embedded compiler in MSan builds

The reference requires nonzero CompiledFunctionRows, but contrib/llvm-project-cmake/CMakeLists.txt also disables the embedded compiler by default for MSan. Setting compile_expressions = 1 cannot enable compilation in that binary. Consequently, the first query produces compiled/interpreted counts 0/3000 instead of 3000/0, and the mixed query produces 0/4000 instead of 3000/1000, so the new test deterministically fails in the MSan stateless lane.

Please add the necessary no-msan tag, as in 04930_jit_compiled_if_date_to_datetime.sql, or make the assertions account for whether the embedded compiler is available while preserving the absolute assertions on JIT-enabled builds.

@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8e30ed0a8 with master bdbd1b837 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of b02fbee24; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

11 translation units recompiled, 35 s compile time in total, 11 of them have a recent master baseline.

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse-keeper ProfileEvents::global_counters_storage 14.25 MiB 14.31 MiB +64.00 KiB (+0.44%)
programs/clickhouse ProfileEvents::global_counters_storage 14.25 MiB 14.31 MiB +64.00 KiB (+0.44%)

Job report

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant