Skip to content

Add parser memory comparison job implementation - #96199

Merged
qoega merged 46 commits into
masterfrom
ci/parser-memory-check
Aug 5, 2026
Merged

qoega merged 46 commits into
masterfrom
ci/parser-memory-check

Conversation

@qoega

@qoega qoega commented Feb 6, 2026 •

Copy link
Copy Markdown
Member

Adds the parser-memory comparison job implementation and its unit tests without
registering or running the job in any CI workflow.

The job profiles SQL parsing allocations with clickhouse-examples, compares
the PR binary with the merge-base master artifact, correlates stacks across
different symbolization modes, and produces per-query tables and flamegraphs.

CI activation is intentionally deferred to a separate, short-lived PR after
this implementation merges. This keeps frequently changing public and private
CI configuration files out of the long-lived implementation review.

Changelog category (leave one):

  • CI Fix or Improvement

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

Not applicable.

Version info

  • Merged into: 26.8.1.832 (included in 26.8 and later)

@clickhouse-gh

clickhouse-gh Bot commented Feb 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e8b724b]

Summary: ✅


AI Review

Summary

This PR adds the standalone implementation of the parser-memory comparison job and its focused unit tests, while deferring workflow activation to a follow-up PR. The current code still has two material issues: one supported CI checkout mode cannot resolve a valid master baseline, and one reporting path can attach an aggregated byte delta to the wrong stack label.

Missing context / blind spots
  • ⚠️ I could not run ci/tests/test_parser_memory_check.py as a pytest suite in this environment because the pytest module is unavailable here, so I validated the remaining issues by tracing the current code and running focused Python repros directly against ci/jobs/parser_memory_check.py.
Findings

⚠️ Majors

  • [ci/jobs/parser_memory_check.py:69] get_merge_base_profiler_url trusts master_track_commits_sha unconditionally, but store_data.py populates that key from git rev-parse HEAD^1, which is only the master parent when PR CI uses the synthetic merge ref. The workflow also supports DISABLE_CI_MERGE_COMMIT=1; in that mode HEAD^1 is just the PR commit's parent, so this job probes REFs/master/<pr-parent-sha>/build_arm_release/clickhouse-examples and fails with No master clickhouse-examples artifact was found. Suggested fix: add the same GitHub-API merge-base fallback already used in ci/jobs/llvm_coverage_job.py / ci/jobs/scripts/job_hooks/promql_compliance_s3.py, and cover the raw-PR-head checkout mode with a regression test.

  • [ci/jobs/parser_memory_check.py:359] aggregate_canonical_stacks correctly sums every stack that collapses to one canonical key, but display_map[key] = s keeps only the last formatted label. Because compute_diff sorts stacks by |diff| before they reach this helper, the surviving label is typically the smallest contributor in the merged group rather than the dominant one. A current-code repro is compute_cross_version_diff([(100, "big stack", [], ["DB::A", "DB::B"]), (10, "small stack", [], ["DB::A", "DB::B"])], []) == [(-110, 110, 0, "small stack")]. The byte totals stay correct, but the HTML diff table points triage at the wrong allocation site. Suggested fix: retain the display string from the largest-|bytes| contributor for each canonical key, or render the canonical form / all merged displays, and add a focused regression test.

Final Verdict

Request changes.

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Feb 6, 2026
qoega added 15 commits February 6, 2026 20:33
Made-with: Cursor

# Conflicts:
#	.github/workflows/pull_request.yml
#	ci/defs/defs.py
#	ci/defs/job_configs.py
#	ci/workflows/pull_request.py
#	src/Common/Jemalloc.cpp
#	src/Common/Jemalloc.h
#	src/Parsers/examples/parser_memory_profiler.cpp
The merge with master replaced parser_memory_profiler.cpp with master's
version, which moved symbolization from Jemalloc.h to JemallocProfileSource.h
but lost the --symbolize-batch CLI mode needed by the CI script.

Re-adds --symbolize-batch using the new symbolizeJemallocHeapProfile() API.
The global SymbolizationLRUCache handles cross-file address deduplication.
Also removes unused run_profiler_with_heap() from the CI script.

Made-with: Cursor
Made-with: Cursor

# Conflicts:
#	src/Parsers/examples/parser_memory_profiler.cpp
…s --symbolize-batch

The parser_memory_profiler binary is PIE (position-independent executable)
on aarch64 builds, so ASLR randomizes the base address on each invocation.
This means addresses in heap files from one process cannot be symbolized
by a different process invocation (--symbolize-batch), resulting in '??' stacks.

Fix: pass --profile --symbolize together so symbolization happens in the
same process that generated the heap profile, where addresses are valid.

Made-with: Cursor
Revert the in-process symbolization workaround back to the 3-phase
batch approach: (1) profile queries, (2) batch-symbolize all heap
files in a single --symbolize-batch call, (3) analyze results.

The batch approach is much faster (~3 min vs ~3 hours) because it
resolves DWARF symbols once per binary instead of per-query. It
requires the parser_memory_profiler binary to be non-PIE (fixed
addresses), which is addressed in a separate PR.

Made-with: Cursor
Made-with: Cursor

# Conflicts:
#	.github/workflows/pull_request.yml
#	ci/workflows/pull_request.py
@qoega
qoega marked this pull request as ready for review March 9, 2026 20:54
@qoega
qoega requested a review from azat March 9, 2026 20:54
@qoega

qoega commented Mar 9, 2026 •

Copy link
Copy Markdown
Member Author
Screenshot 2026-03-09 at 21 54 53

Comment thread ci/jobs/parser_memory_check.py Resolved
Comment thread ci/jobs/parser_memory_check.py Resolved

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks useful, but I have couple of questions and comments

Questions:

  • What does status shows? What percentage of difference?

Comments:

  • Let's download not the latest master, but the merge base

  • Let's move list of queries into a separate file

  • The report should use full width

Image

Comment thread ci/jobs/parser_memory_check.py Outdated
"main",
"(anonymous namespace)::dumpProfile",
"dumpProfile",
"kdf_sshkdf_free",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is likely due to wrong resoling, let's remove this to know that we have this bug

Each expanded query row now shows:
- Cross-version diff table (PR minus Master per stack)
- PR allocation flamegraph (server-side SVG icicle chart)
- Individual profiles (existing, preserved)

Made-with: Cursor
Comment thread ci/jobs/parser_memory_check.py Outdated
status = "OK"
total_improvements += 1
else:
status = "OK"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Result status uses wrong string constants

High Severity

The per-query Result objects are created with plain string statuses "FAIL" and "OK" (lines 995, 998, 1001), but the rest of the file and codebase consistently uses Result.Status.FAILED and Result.Status.SUCCESS constants (see lines 841, 850, 855, 929, 932, 955, 1078, 1080). If these constants differ from the plain strings (which is very likely — e.g. Result.Status.FAILED is probably "failure" not "FAIL"), every per-query Result will carry an invalid status, breaking CI report rendering and status aggregation.

Additional Locations (1)
Fix in Cursor Fix in Web

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"OK" -> Result.StatusExtended.OK

Comment thread ci/jobs/parser_memory_check.py Resolved
Comment thread ci/jobs/parser_memory_check.py Resolved
@qoega qoega changed the title wip: parser memory CI check Parser memory CI check Mar 12, 2026
Made-with: Cursor

# Conflicts:
#	.github/workflows/pull_request.yml
Comment thread ci/jobs/parser_memory_check.py Resolved
Comment thread ci/jobs/parser_memory_check.py Resolved
qoega added 2 commits July 29, 2026 12:09
# Conflicts:
#	.github/workflows/pull_request.yml
Use `clickhouse-examples` published by the ARM release build for the PR artifact dependency and master lookup. Remove the redundant examples target from `arm_binary` and fail the check when no reference artifact can be resolved.

CI: https://s3.amazonaws.com/clickhouse-test-reports/PRs/96199/ebbae7f1776ece4e50c423e2f03ab7d210b819d6/parser_memory_check/job.log

Related: #111398
Comment thread ci/jobs/parser_memory_check.py Resolved
@qoega

qoega commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Do not analyze missing symbolized heap profiles or publish misleading green query results after `batch_symbolize` fails. Clean the temporary heap profiles and finish the job immediately with the existing failure result.

Add a regression test that verifies analysis and HTML report generation are not called on this path.

Review: #96199 (comment)
CI: https://s3.amazonaws.com/clickhouse-test-reports/PRs/96199/ebbae7f1776ece4e50c423e2f03ab7d210b819d6/parser_memory_check/job.log
Iterates master_track_commits_sha (like performance_tests.py) to find
the closest available build. Returns empty string if none found."""
info = Info()
commits = info.get_kv_data("master_track_commits_sha") or []

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.

get_merge_base_profiler_url currently depends entirely on master_track_commits_sha. In PR CI that key is populated by store_data.py from git rev-parse HEAD^1, but the workflow also supports DISABLE_CI_MERGE_COMMIT=1, which checks out the raw PR head instead of the synthetic merge ref. In that mode HEAD^1 is just the PR commit's parent, so this loop ends up probing REFs/master/<pr-branch-sha>/build_arm_release/clickhouse-examples and eventually fails with No master clickhouse-examples artifact was found.

Could we add the same GitHub-API fallback that promql_compliance_s3.master_track_commits / llvm_coverage_job.get_git_info use, so the baseline lookup stays valid in both checkout modes?

Match stacks using one primary symbol per physical backtrace address so DWARF inline expansions in master correlate with stripped PR symbols. Normalize LLVM clone suffixes while retaining full inline stacks for display and detailed allocation flamegraphs.

Exclude stacks containing `dumpProfile` from measured totals and differential flamegraphs because profile filename construction is profiler bookkeeping, not parser memory.

Report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/96199/cd143e56627fbed82d9a5295e4733fe6c060efa5/parser_memory_check/parser_memory_report.html
scanhex12 pushed a commit to scanhex12/ClickHouse that referenced this pull request Jul 29, 2026
Build and publish the `clickhouse-examples` multicall binary from the PR and master ARM release jobs. Keep backport and release-branch jobs unchanged to avoid unnecessary artifact uploads.

Related: ClickHouse#96199

CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/96199/ebbae7f1776ece4e50c423e2f03ab7d210b819d6/parser_memory_check/job.log
display_map = {}
for b, s, _full, canonical in stacks:
key = tuple(canonical)
byte_map[key] = byte_map.get(key, 0) + b

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.

aggregate_canonical_stacks sums all stacks that collapse to one canonical key, but display_map[key] = s keeps only the last label. Because compute_diff sorts stacks by |diff| before they reach this helper, the surviving label is usually the smallest contributor in that merged group rather than the dominant one.

A minimal repro on the current code is:

compute_cross_version_diff(
    [
        (100, "big stack", [], ["DB::A", "DB::B"]),
        (10, "small stack", [], ["DB::A", "DB::B"]),
    ],
    [],
)
# [(-110, 110, 0, "small stack")]

The row reports 110 B but points at small stack, which can send triage to the wrong allocation site. Please keep the largest-|bytes| representative (or render the canonical form / all merged displays) when aggregating a canonical key.

@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This PR is CI-infrastructure-only: it adds a "Parser memory check" job with its supporting script and tests, and cleans up a build-target special case. None of these changes touch the server's query-execution path, so no clickbench query delta can be attributed to it. The flagged Q15 "improvement" (-13.5%) is downgraded to not_sure as run-to-run variance, and the Q30/Q31/Q32 deltas are consistent with normal noise (Q30 and Q31 fall inside master's current variance band, Q32's two tests disagree). The envelope suppressions look correct given the diff.

clickbench

⚠️ 4 inconclusive

Flagged queries (4 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 15 not_sure 223 193 -13.5% <0.0001 This PR only adds a CI parser-memory-check job plus a build-target cleanup; nothing touches server query execution, so the -13.5% on Q15 is run-to-run variance, not a real improvement.
⚠️ 30 not_sure 268 296 +10.4% <0.0001 The +10.4% sits inside master's current variance band, and a CI-only change cannot affect this query's execution path, so this is noise.
⚠️ 31 not_sure 376 424 +12.8% <0.0001 The +12.8% is within master's variance band; a CI-plumbing-only PR cannot touch this query path, so treat it as noise.
⚠️ 32 not_sure 1352 1275 -5.7% 0.0114 The two tests disagree and the PR changes only CI plumbing, so the -5.7% is not a real PR effect.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 92174919-701b-4be9-8c38-0f3893d39589
  • MIRAI run: d7b6ee4a-4310-4b80-b482-9bd4dd8a5e8a
  • PR check IDs:
    • clickbench_1496793_1785769742
    • clickbench_1496799_1785769742
    • clickbench_1496817_1785769742
    • tpch_adapted_1_official_1496825_1785769743
    • tpch_adapted_1_official_1496836_1785769742
    • tpch_adapted_1_official_1496863_1785769743

qoega added 2 commits August 5, 2026 12:37
Keep the parser memory job and its tests in this PR, but restore workflow generation, job registration, and build configuration to `master`. The activation will follow in a short-lived PR after this implementation merges.
@qoega qoega changed the title Parser memory CI check Add parser memory comparison job implementation Aug 5, 2026
@clickhouse-gh clickhouse-gh Bot added pr-ci and removed pr-build Pull request with build/testing/packaging improvement labels Aug 5, 2026
@qoega
qoega added this pull request to the merge queue Aug 5, 2026
Merged via the queue into master with commit ae81f63 Aug 5, 2026
179 checks passed
@qoega
qoega deleted the ci/parser-memory-check branch August 5, 2026 13:30
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 5, 2026
pull Bot pushed a commit to peijunlin2008/ClickHouse that referenced this pull request Sep 7, 2026
Bundle the stateful profiler in clickhouse-examples and add a separate report job that reuses the parser memory check's stack correlation and flamegraph helpers.

Related: ClickHouse#96199

Reference report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/96199/cd143e56627fbed82d9a5295e4733fe6c060efa5/parser_memory_check/parser_memory_report.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants