{{ message }}
Repository navigation
perf(postgres): reduce per-record allocations in the CDC pull path - #4920
Open
lukejudd-lux wants to merge 1 commit into
Open
lukejudd-lux wants to merge 1 commit into
lukejudd-lux wants to merge 1 commit into
Conversation
lukejudd-lux
temporarily deployed
to
external-contributor
October 14, 2026 05:33 — with
GitHub Actions
Inactive
lukejudd-lux
had a problem deploying
to
external-contributor
October 14, 2026 05:33 — with
GitHub Actions
Failure
dtunikov
reviewed
Oct 14, 2026
dtunikov
approved these changes
Oct 14, 2026
Two spots in the per-WAL-record path (PullCdcRecords) allocate more than they need to. In a CPU/heap profile of a Postgres source mirror both are a meaningful share of allocations, and the CPU profile is dominated by GC/malloc, so trimming them frees CPU. - processMessage called internal.LoggerFromCtx(ctx) on every message, which goes through temporal log.With and allocates per call. The logger is already built once in PullCdcRecords; pass it in as a parameter. - The unchanged-toast metric was recorded with UnchangedToastValuesCounter.Add plus a fresh attribute.NewSet on every update record. Accumulate the counts in atomics and flush them once a minute with the other CDC counters, reusing two pre-built attribute sets (same pattern already used for FetchedBytesCounter). No behaviour change: same logs, same metric values, fewer allocations.
lukejudd-lux
force-pushed
the
perf/cdc-reduce-per-record-allocs
branch
from
October 14, 2026 21:37
68c7922 to
66587da
Compare
lukejudd-lux
requested a deployment
to
external-contributor
October 14, 2026 21:37 — with
GitHub Actions
Waiting
lukejudd-lux
temporarily deployed
to
external-contributor
October 14, 2026 21:37 — with
GitHub Actions
Inactive
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Was profiling a Postgres source mirror and noticed CPU is mostly GC/malloc, with a couple of avoidable allocations on the per-record path in PullCdcRecords.
Two small fixes:
processMessage was rebuilding the logger from context on every message. It's already available in PullCdcRecords, so pass it down instead.
The unchanged-toast metric was recording with a freshly built attribute set on every update record. Accumulate the counts and flush them once a minute with the other CDC counters, the same way fetched bytes and friends are already handled.
No behaviour change, just fewer allocations on the hot path.