Repository navigation
Extend NOOP CRCs past the length cache - #237
Open
iskakaushik wants to merge 1 commit into
Open
iskakaushik wants to merge 1 commit into
iskakaushik wants to merge 1 commit into
Conversation
This was referenced Oct 20, 2026
A NOOP's body is its main-data marker followed by zeros, so its CRC32C depends on its length alone. The filter caches it by length for bodies under 8 KiB and hashes every other body in full, zeros included. Compute a body the cache lacks by extending the CRC of its marker over the zeros instead: one GF(2) operator per power-of-two length, applied as four table lookups per set bit of the length. Every length then costs the same, which a NOOP covering a whole run of dropped records needs, and the cache keeps the common lengths at a single load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iskakaushik
force-pushed
the
noop-crc-zero-extension
branch
from
October 20, 2026 06:53
953e03b to
f2022ce
Compare
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.
Part of #223 (D in its design), first of a stack of four.
A NOOP's body is its main-data marker followed by zeros, so its CRC32C depends
on its length alone. The filter caches it by length for bodies under 8 KiB and
hashes every other body in full, zeros included.
This computes a body the cache lacks by extending the CRC of its marker over the
zeros: one GF(2) operator per power-of-two length, applied as four table
lookups per set bit of the length. Every length then costs the same, which the
next PR needs for a NOOP covering a whole run of dropped records, and the cache
keeps the common lengths at a single load.
A first version replaced the cache with zero extension outright. On the
lifecycle repro (below) that cost the pump about 23 ns per record, roughly
5%, since nearly every dropped record there is a cache hit; so the cache
stays.
The stack
Each is one idea and under 1,000 changed lines. Merging comes before either
compact form because it turns the padding into a few long zero runs per page,
which is what makes both small. The
--out-dirchange comes before the wirechange: the measured bottleneck is disk writes, while the wire is loopback and
costs about 1.5% of a core.
Why
The issue's first premise was CPU: sending to the shadow turned out to cost
about 1.5% of a core. A production deployment shows the real cost is disk
bytes:
EBS volume: the daemon's
--out-dirsegments, the shadow'spg_wal, andthe shadow's zero-fill of each new segment.
EBS burst credits and is capped at 312.5 MB/s, about 100 MB/s of source
WAL. The shadow's TOAST reads queue behind those writes: fetch latency
rises from about 120 µs to 250-800 µs.
--out-dirand on thewire, are NOOP padding.
So the win is fewer bytes written to walshadow's own disk and sent on the
wire, plus less replay work on the shadow.
Tests
zero_extension_matches_hashing_the_zeros:crc32c_zerosequals CRC32C overthe actual zeros for every power-of-two length ±1, the SHORT/LONG marker
switch and 2,000 random lengths up to 1 MiB, from random starting CRCs.
noop_of_any_length_parses_with_a_valid_crc: a NOOP of each of those lengths,twice so the second pass reads the cache, parses as
XLOG_NOOPwithxl_prevkept and a CRC PostgreSQL accepts.
WALSHADOW_REQUIRE_TOOLS=1, merged coverage andlint; fmt, clippy
-D warnings.Benchmark
Setup. ceramic (
bench/ceramicfrom the ceramic-reproducer branch: PG 18,[toast] mode = "shadow", a fixed 4.0 GiB backlog of 5.64M records), daemonpinned to 8 CPUs,
ab.sh <parent> <this> 4interleaved, mean ± stdev, on a64-vCPU dev VM with an EBS root volume. The VM first assigned picked up an
unrelated disk-heavy benchmark partway through, so every number here comes
from a second, idle VM of the same shape. Disk bytes are
/proc/<pid>/iowrite_byteslesscancelled_write_bytesover the drain, per source WAL bytedrained: the daemon, and the shadow's postmaster with its children. "Sent" is
the walsender socket's
bytes_sentper backlog byte. On this VM ceramic isbound by TOAST fetch latency (about 200 µs a fetch; the pump waits on a full
queue 83% of the time), not by CPU, so rec/s barely moves unthrottled.
The lifecycle repro is the issue's workload (PG 17, one wide table with five
btree indexes, an insert and two non-HOT updates per transaction, 10 s of
pgbench, about 2.8 GiB of WAL at 113 B/rec, no TOAST). It is pump-bound at
about 1.8M rec/s, so the pump thread's CPU per record is the number to watch;
its drain time steps in about 1 s increments with the source's status
cadence, so its MiB/s does not resolve a few percent.
ceramic, main vs this PR:
Lifecycle repro, pump thread per record over three interleaved runs: main
427 ± 16 ns, this PR 438 ± 5 ns. Replacing the cache outright measured
447 ± 8 ns.
🤖 Generated with Claude Code