Repository navigation
Conversation
…disabled Every `RapidJSONParser::parse` called `document.ParseStream`, which builds a fresh `GenericReader` whose 256-byte stack is allocated on first push and freed when the reader dies, and which frees the document's own 1024-byte stack in `ClearStack` -> `ShrinkToFit` after every document. So each parsed document cost two malloc/free pairs through `RapidJSONMemoryTrackerAllocator`, `DB::Allocator`, the memory tracker and jemalloc: about 19% of the cycles of `json_extract_rapidjson` query ClickHouse#4, and the code where the slow CI layouts of that query take their uop-cache misses (the red `Performance Comparison` job on ClickHouse#118008: same instructions as a fast PR build, 80x more DSB misses). `RapidJSONStackAllocator` is the document's `StackAllocator`; rapidjson passes the same instance to the reader it creates in `ParseStream`. Blocks come from a 2 KB buffer inside the parser that `parse` rewinds before each document. Blocks that do not fit, and every growth past the buffer, go to `RapidJSONMemoryTrackerAllocator` as before, so large documents are tracked and bounded exactly as today. Inline blocks carry a zero size header, which is how the static `Free` tells them from heap blocks (whose size is never 0). Rewinding is safe because nothing outlives `ParseStream` in those stacks: the document stack is freed by `ClearStackOnExit` on every exit, including exceptions, the reader is a local of `ParseStream`, and strings and members are copied into the value pool. Alternatives not taken: `MemoryPoolAllocator` as the stack allocator never frees a block on `Realloc`, which roughly doubles peak tracked memory for a large flat document; a persistent reader with `Populate` keeps the document stack being freed; patching rapidjson's `ShrinkToFit` changes every user of the library. Measured on a non-LTO release build, one pinned CPU: `json_extract_rapidjson` #0..ClickHouse#4 take 0.82-0.87x the time (instructions of ClickHouse#4 -20%), ClickHouse#5..ClickHouse#13 0.95-0.99x, ClickHouse#14 1.01x across 9 link layouts; the smallest `max_memory_usage` that parses a 2M-element array (80 MB) or a 20 MB string (122 MB) is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the RapidJSONStackAllocator class and header-tag comments to one line each; drop the Realloc note implied by the class comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261003-203100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261003-184000 |
|
Workflow [PR], commit [f2f5e7a] Summary: ✅
AI ReviewSummaryThe PR serves RapidJSON parsing stacks from a reusable 2 KB inline buffer, retaining memory-tracked heap allocation for larger documents. Reviewed all changed files, the pinned RapidJSON implementation, affected callers, and all prior discussion against head Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; current-head CI remains pending. |
Build profile diff (arm_release)Commit See the job log for details. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
CI finish ledger - 0095713Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261004-013156 |
…ck-inline-buffer Picks up ClickHouse#123738 (Build (amd_fuzzers) clickhouse_fuzzer link overflow). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Fixing PR for 05293_keeper_map_replica_recovery_keeps_data (timeout in the arm_binary AsyncInsert lane) created: #123816 |
CI finish ledger - b6604bbEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 146 check runs completed, Session id: cron:our-pr-ci-monitor:20261004-070344 |
05293_keeper_map_replica_recovery_keeps_data and 04651_timeseries_recover_lost_replica detected the end of a forced Replicated database recovery by counting the line "All tables are created successfully" in system.text_log. The filter is on logger_name/message, not on the table key, so every count was a full scan of the server-wide log: 3 per run in 05293, 7 in 04651. In Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel) on ClickHouse#123755 the log had 12-14M rows on the s3 disk and, with the randomized read settings, each scan took about 220 s, so 05293 hit the 600 s timeout while the recovery itself had finished in about 30 ms. 04651 failed 8 times in 30 days in the amd_tsan flaky check with "Test runs too long". DatabaseReplicated::recoverLostReplica rewrites the replica digest node as its last step, and both tests arm the recovery by setting that node to 42 right before DETACH/ATTACH DATABASE. Poll that node through system.zookeeper instead: one Keeper read per poll, independent of the log size and of the storage. The signal is later than the old log line, so the assertions that follow see at least as much finished state. 04651 keeps its three log-line checks and bounds them to rows written since the test started. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
|
Related: #118008 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
JSONExtract*functions and theJSONtype withallow_simdjson = 0no longer allocate memory for each parsed document: rapidjson's parse stacks now start in a buffer inside the parser, which makesJSONExtract*on small documents about 15% faster.Description
json_extract_rapidjson #4was red inPerformance Comparison (amd_release, master_head, 3/6)on #118008 (report, +28%) and on 8 other PRs the same day. The slow PR binaries run the same instructions as fast ones but miss the uop cache 80x more often, and most of those misses are in the per-document allocation code of the rapidjson parser.That code runs because each
RapidJSONParser::parsemakes rapidjson allocate and free two stacks through the memory tracker: the stack of the reader thatParseStreamcreates, and the document's own stack, whichParseStreamfrees after every document. It is 14% of the cycles of that query in a fast build and 19% in a slow one.RapidJSONStackAllocatorserves both stacks from a 2 KB buffer inside the parser, rewound before each document. Blocks that do not fit go toRapidJSONMemoryTrackerAllocatoras before, so large documents are tracked and bounded as today.Validation, non-LTO release build, one CPU, medians of 3 rounds:
json_extract_rapidjsonqueries #0..doc: fix typo #4: 0.82-0.87x time (instructions of doc: fix typo #4: -20%); Extra include for std::mt19937_64 #5..Update Docker files for Docker Hub #13: 0.95-0.99x; Comparison with ElasticSearch #14 (200 members): 1.01x across 9 link layouts.max_memory_usagethat parses a 2M-element array or a 20 MB string is unchanged (80 MB, 122 MB).--shuffle-sectionslayouts did not reproduce the CI slowdown (base spread 1.05x), so this makes the query faster and removes the allocator code from its hot loop, but I cannot show that it makes the query immune to such layout flips.05320_rapidjson_parse_stack_reusemixes documents that fit the buffer with ones that outgrow it in one block.Workflow [PR]
Sync PR [sync-upstream/pr/123755]