Skip to content

Skip CustomSeparated fields without the generic escaping-rule dispatcher - #131462

Merged
alexey-milovidov merged 1 commit into
masterfrom
customseparated-skip-field-direct
Nov 14, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
customseparated-skip-field-direct

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Reading a few columns from a wide CustomSeparated file spends most of its time skipping the other fields. For each skipped field the reader went through skipFieldDelimiter -> assertString -> checkString and skipField -> skipFieldByEscapingRule -> readEscapedStringIntoImpl. skipFieldByEscapingRule is a small out-of-line switch that tail-calls the reader. With -mbranch-protection=pac-ret (#119685), every field then adds a serial autiasp -> paciasp dependency on the return address. In the PR binary, autiasp and the branch after it take 65% of the samples of skipFieldByEscapingRule.

Measured on Neoverse V2 with the CI arm_release binaries of #119685 (f0318667) and its master base (485f00de), single-threaded, 100k rows of hits (105 columns), user cycles:

query master pac-ret change
SELECT WatchID from CustomSeparatedWithNames 2.96G 3.74G +25% (instructions +4.5%)
SELECT WatchID from TabSeparatedWithNames 2.37G 2.39G +1%

This matches the formats_columns_sampling #1 and count_from_formats CustomSeparated slowdowns (+22-26%) flagged on every head of #119685. TabSeparatedFormatReader::skipField calls readEscapedStringInto directly and checks its delimiter with assertChar, so it barely changes.

This PR does the same for CustomSeparated: the Escaped and Raw rules read the skipped field directly, and a one-character field delimiter is checked inline with assertChar. Other escaping rules and multi-character delimiters keep the previous path, so behaviour does not change. The new test 05632_custom_separated_skip_fields covers skipping columns and rows for every escaping rule, with one- and multi-character delimiters. Its reference was produced by the current master binary.

I could not get a clean local A/B timing of the change: the shared build I relinked against was being rebuilt by another job, so the relinked binaries had inconsistent archives. The ARM performance comparison of this PR measures the effect without pac-ret, and #119685 measures it with pac-ret after this is merged.

Related: #119685
Related: #130965

Changelog category (leave one):

  • Performance Improvement

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

Faster reading of a subset of columns from CustomSeparated formats with the Escaped or Raw escaping rule.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.2280-master (included in 26.11 and later)

…tcher

Reading a few columns from a wide `CustomSeparatedWithNames` file spends
most of its time skipping fields. Each skipped field went through
`skipFieldDelimiter` -> `assertString` -> `checkString` and
`skipField` -> `skipFieldByEscapingRule` -> `readEscapedStringIntoImpl`.
`skipFieldByEscapingRule` is a small out-of-line switch that tail-calls the
reader, so with `-mbranch-protection=pac-ret` every field adds a serial
`autiasp` -> `paciasp` dependency on `x30`. On Neoverse V2 this made
`formats_columns_sampling` and `count_from_formats` on `CustomSeparated`
20-25% slower in #119685,
while `TabSeparatedWithNames`, whose `skipField` calls the reader directly,
changed by 1%.

Read `Escaped` and `Raw` fields directly, as `TabSeparatedFormatReader::skipField`
does, and check a one-character field delimiter with the inline `assertChar`.
Other escaping rules and multi-character delimiters keep the previous path.

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

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b805429]

Summary: ✅


AI Review

Summary

This PR bypasses the generic escaping-rule dispatcher for skipped Escaped and Raw fields in CustomSeparated and specializes single-character delimiter checks. The new regression test passes in Fast test at b805429b839b0d792f2464f881301518f4f82c00. ⚠️ Request changes until measurements establish the net performance benefit of this patch.

Findings

⚠️ Majors

  • src/Processors/Formats/Impl/CustomSeparatedRowInputFormat.cpp:167: The claimed performance improvement lacks a matched base/head measurement. The supplied cycle counts measure the regression from Enable -mbranch-protection=pac-ret on ARM #119685, and the description reports that this patch's local A/B measurements were unusable. This is material because the generic helper deliberately shares NullOutput to avoid stack-protector instrumentation, while the new path passes a stack-local object's address to out-of-line readers. Removing dispatch may trade against additional per-field overhead. Attach a matched ARM release comparison and address overhead if the results require it.
Tests
  • ⚠️ Provide before/after results for formats_columns_sampling and count_from_formats with identical compiler flags. The selected ARM and AMD performance jobs are still pending in the CI report, and the performance dashboard has no run for this PR yet. Completed CI measurements can close this evidence gap; no additional functional test is requested.
Final Verdict

Status: ⚠️ Request changes. Minimum action: demonstrate the net speedup of the actual patch with matched ARM release measurements; adjust the implementation only if those measurements expose a regression.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 13, 2026
/// Skipping is the main cost of reading a few columns from a wide file, so the `Escaped` and `Raw`
/// rules read the field directly, as `TabSeparatedFormatReader::skipField` does, instead of going
/// through the generic `skipFieldByEscapingRule` for every field.
NullOutput out;

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.

[Major] Measure the net benefit of the new per-field path

The supplied cycle counts compare #119685 with its base; they establish the motivating regression, but do not measure this patch. The description explicitly says its local A/B result was unusable, and this head's performance comparisons are still pending.

That distinction matters here: skipFieldByEscapingRule deliberately uses a shared NullOutput to avoid -fstack-protector-strong instrumentation (see src/Formats/EscapingRuleUtils.cpp:70-78), whereas this replacement passes a stack-local object's address to the out-of-line readers. Removing the dispatcher can therefore trade against additional per-field overhead; the speedup needs verification.

Please attach a matched ARM release base/head comparison using formats_columns_sampling and count_from_formats, with identical compiler flags, and address any overhead from the local NullOutput that the measurements reveal. The existing performance jobs can supply the evidence once completed.

@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Nov 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b805429b8 with master 5d2e2113b (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 5b357bdc2; 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

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

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Nov 14, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 14, 2026
Merged via the queue into master with commit bdb031a Nov 14, 2026
208 checks passed
@alexey-milovidov
alexey-milovidov deleted the customseparated-skip-field-direct branch November 14, 2026 02:53
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-performance Pull request with some performance improvements 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.

2 participants