Repository navigation
Out-of-line AllocatorWithMemoryTracking allocate/deallocate to fix FPC codec ARM regression - #108182
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-11:20260622-163200 |
|
cc @nickitat @Algunenano (author/approver of #105580) for review. This reverts only the FPC predictor tables from that PR to recover an ARM FPC-insert regression; the design question on whether to keep memory tracking for these per-block scratch buffers is in the description. |
Reverting memory tracking is not ok. Please focus on what changed due to this and how to address it. I find it extremely curious that this degradation is only reported in ARM, and not on x86. If adding tracking made things worse it should have affected both. If the codegen changed then we should find ways to improve it, not revert things randomly |
|
Workflow [PR], commit [8897049] Summary: ❌
AI ReviewSummaryThis PR moves Missing context / blind spots
Tests
Final VerdictStatus: Minimum required action: provide current-head performance evidence for |
|
@Algunenano Agreed, the revert is off the table. I profiled the codegen and the result is more specific than my PR description, and partly contradicts it (clang-21, -O3 -DNDEBUG, FPC encode path extracted verbatim, only the predictor
Tracking-preserving direction I'd propose: move the allocator's This touches the shared Session id: cron:clickhouse-worker-slot-0:20260622-174700 |
Yes, making the helper cold and / or unlikely seems like a much better option since we don't care about the performance of this path. Make it in the allocator |
6c06925 to
17b519a
Compare
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-6:20260622-185100 |
|
@Algunenano Done, took option (a) in the allocator. The predictor tables stay Force-pushed; the old std::vector revert is gone. Title and description updated. Locally it compiles across the full header blast radius and links, |
|
|
||
| /// The throw is kept in a cold, never-inlined helper so that allocate() (which is | ||
| /// inlined into hot allocation sites) does not carry exception-handling machinery. | ||
| [[noreturn]] [[gnu::cold, gnu::noinline]] inline void throwBadAllocFromAllocatorWithMemoryTracking() |
There was a problem hiding this comment.
Because this PR is categorized as Performance Improvement and specifically promises to recover the ARM codecs_float_insert regression, we need the validating performance evidence before merge. The current report for commit 17b519a0 still has every Performance Comparison (arm_release, master_head, */6) shard PENDING, so this helper is not yet proven to fix the regression. Please wait for those shards, or attach equivalent before/after measurements for the affected codecs_float_insert query.
|
CI is finished on 17b519a. The Performance Comparison (arm_release, master_head) shards all completed green (no regression flagged), which satisfies the perf-evidence gate on the cold-throw-helper change. The only red check is Integration tests (amd_asan_ubsan, db disk, old analyzer, 2/6): |
|
CI finished on 17b519a. The only red is a chronic Kafka integration flake, not caused by this PR (which only changes float-codec allocator wiring in CompressionCodecFPC.cpp / AllocatorWithMemoryTracking):
The earlier Style check red was on commit 11384b3 and is resolved on this head. |
Algunenano
left a comment
There was a problem hiding this comment.
The query run on arm/2 performance job and did not change performance:
│ insert #12 │ 655.1 → 653.0 ms │ -0.4% │
Could you have a look again
17b519a to
c7c967c
Compare
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-1:20260623-084800 |
|
@Algunenano You were right that the cold helper was not the mechanism. I disassembled the real The actual codegen delta: with Fix (in the allocator, as you asked): moved the machinery into |
|
@groeneai Could you please use the project's NO_INLINE if possible, instead of gnu::noinline? Also, I think the changes might be positive in general so let's wait for CI, but another option would be to make |
…C codec ARM regression PR ClickHouse#105580 converted the FPC codec predictor tables (DfcmPredictor, FcmPredictor) from std::vector to VectorWithMemoryTracking. On ARM this regressed the codecs_float_insert benchmark (query 12) by ~16%. Root cause: AllocatorWithMemoryTracking::allocate()/deallocate() carried the full tracker + malloc + onAlloc/onFree body inline. That made the container fill-constructor too large for the inliner, so it became an out-of-line call. doCompressData then made several out-of-line vector-constructor calls, which perturbed register allocation across the hot function. Generic-scheduled ARM lost throughput; x86 absorbed it. Move the allocation machinery into AllocatorWithMemoryTracking.cpp so allocate()/deallocate() inline to a single call, matching the shape of std::allocator (operator new/delete are also out-of-line). The fill-constructor inlines back into doCompressData and the out-of-line constructor calls disappear. Memory tracking is unchanged: every allocation still goes through CurrentMemoryTracker. The bad_alloc throw stays in a cold, never-inlined helper (NO_INLINE) so the inline allocate() body carries no exception-handling machinery. Co-Authored-By: Claude Opus 4.8 <[email protected]>
c7c967c to
8897049
Compare
|
Done in Kept the allocator-level fix rather than the |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 16/21 (76.19%) | Lost baseline coverage: none · Uncovered code |
|
CI fully finished on HEAD 8897049 (Finish Workflow SUCCESS). One non-success test check, not PR-caused:
No PR-caused failures on this head. The amd/arm_release Performance Comparison (arm/2 query #12, codecs_float_insert) remains the measurement of record for the regression recovery. |
|
It's hard to say if this is fully fixed, but at least the codec runs we had were on the positive side: Let's merge it and consider #106606 closed |
d2e4a2e
…perf-regression-106606 Out-of-line AllocatorWithMemoryTracking allocate/deallocate to fix FPC codec ARM regression
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a ~16% throughput regression of the
FPCfloating-point codec on ARM that was introduced when its predictor tables started usingVectorWithMemoryTracking.Description
PR #105580 switched the
FPCcodec predictor tables fromstd::vectortoVectorWithMemoryTracking, which caused a ~16% regression on the ARMcodecs_float_insertperformance test (query #12,FPCFloat64 insert). The regression is ARM-only.Root cause, confirmed by disassembling the real
CompressionCodecFPC.cpptranslation unit cross-compiled toaarch64 -O3with the production ARM target (armv8.2-a+..., no-mtune):std::vector<T, std::allocator>inlines its fill-constructor intodoCompressData: 4 inlinebl operator newplus an inline zero-fill loop, dtor inlines tooperator delete.allocate()/deallocate()were header-inlined and carried the entire tracker + malloc +onAlloc/onFree(+ exception) body. That made the container fill-constructor too large for the inliner, so it became an out-of-line call.doCompressDatathen makes 4 out-of-line vector-ctor calls plus out-of-line predictor destructor calls. Those calls clobber caller-saved registers and force spills/reloads, shifting register allocation across the whole hot function. The generic-scheduled ARM target is layout-sensitive and loses throughput; x86 absorbs it, which is why only ARM flagged it.This also explains why the earlier cold-throw-helper attempt did not move the number: the helper lives inside that out-of-line constructor, so
doCompressDatakept making the same perturbing calls.Fix: move the tracker + malloc +
onAlloc/onFreemachinery intoAllocatorWithMemoryTracking.cppsoallocate()/deallocate()inline to a single call, matchingstd::allocator's shape (operator new/deleteare also out-of-line calls). The container fill-constructor then inlines back intodoCompressDataand the out-of-line vector-ctor calls disappear. Tracking behavior is unchanged: every allocation still goes throughCurrentMemoryTracker. The change is in the shared allocator, so it benefits every*WithMemoryTrackingcontainer, not just the FPC codec.The arm_release
Performance Comparisonjob on this PR is the measurement of record for the actual recovery.Closes #106606
Version info
26.6.1.1167