Skip to content

perf(6o-i): cheaper group framing: a byte-loop record check, prebuilt markers, one shared group extent - #200

Merged
akosidencio merged 4 commits into
devfrom
perf/v0.6o-i-group-check
Nov 26, 2026
Merged

akosidencio merged 4 commits into
devfrom
perf/v0.6o-i-group-check

Conversation

@akosidencio

@akosidencio akosidencio commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Phase 6O-I: reduces the transaction-framing costs that PR 6's native campaigns measured. Draft until review E (performance and resources) approves it. Review E round 1 found the code correct and asked for the measurements now running.

What was measured

Base 6O-H 6068337 against 6O-I dev 0a1f95e, 5 interleaved reps:

  • CPU: grouped transactions under AOF everysec cost +5–8% server CPU per transaction, about 48–62 ns per member.
  • Throughput: two-write transactions under everysec lost 9–11% throughput.
  • Primary RSS with a replica: +6 to +13 MiB. Every backlogged frame, grouped or not, carried a 16- to 32-byte group extent.
  • Single replicated writes: each paid two extra allocations in fan_out.

Changes

  • 617aedb. The one-record check each grouped member gets in every build (review A L6) reads lengths byte by byte. Its acceptance is the same, except that a + sign is now refused (RESP never writes one), and it has unit tests. TXN-BEGIN/TXN-COMMIT for groups of 2–64 records come from a table built once.

  • 4d46dbc. An intermediate inline 16-byte group mark, superseded by the next commit.

  • 976574a. Groups live in a side table beside the backlog, one 24-byte entry per group, kept while any of its frames is. ReplFrame is back to 6O-H's 16 bytes, so a non-transactional write pays nothing for 6O-I. Rule 2 does a binary search of the side table, a partial sync gets the groups that start among its frames, and a queued frame carries the group only on the group's first frame. fan_out of one frame uses an inline SmallVec, so it allocates nothing more than before 6O-I. The byte total is u64 again, with no saturation.

  • 785f042. A test only (review E round 2, L5): the side table is trimmed with the backlog. It fails with the trim removed.

Verification

… markers, one shared group extent

The 6O-I campaign (PR 6) measured the grouped AOF path at +5-7.5% server
CPU per transaction, about 52 ns per member: the one-record check each
member gets in every build (review A L6) parsed every length with a window
search and str::parse. It now reads digits byte by byte, with the same
acceptance (plus a sign now refused, which RESP never writes) and unit
tests of its own. TXN-BEGIN/TXN-COMMIT for groups of up to 64 records come
from a table built once instead of being formatted per EXEC.

The same campaign measured +6 to +13 MiB of primary RSS with a replica
attached: every backlogged frame carried a 32-byte group extent (review A
N3). A group's frames now share one Arc'd extent: 8 bytes per frame.
…bytes

The re-measurement showed the shared Arc extent helps large groups only
(primary RSS with a replica, 100-write transactions: 71 -> 62 MiB, base 59)
but not 2-frame ones (72 -> 68 MiB, base 59): 8 bytes inline plus half of a
48-byte allocation per frame. GroupMark is 16 bytes inline, no
allocation: the first offset (NonZeroU64), the count, and the byte total
saturating at u32::MAX (a group that large is refused by every capable
replica, whose bound is 64 MiB, so the header it then declares leads to
the same full sync).
… a single write allocates nothing more

Review E (H2, M2): every replicated write paid for 6O-I. A backlogged frame
carried a group extent (16 to 32 bytes, grouped or not: +7 to +13 MiB of
primary RSS over a full 16 MiB backlog of small frames, growing with the
backlog setting), and fan_out built two Vecs for one frame.

- ReplFrame is back to 16 bytes. The backlog keeps one ReplGroup per group
  in a side table (oldest first, kept while any of its frames is), which
  rule 2 consults (group_of, a binary search); a partial sync gets the
  groups that start among its frames.
- A queued frame carries the group only on the group's first frame, for
  the sender's header.
- publish takes a SmallVec: fan_out of one frame allocates nothing more
  than before 6O-I.
- The byte total is u64 again: no saturation.
L5: no test or mutant covered the side table's trim; a table that never
shrank passed every test. The new test fans out 10,000 two-frame groups
(and single writes) into a 1,000-byte backlog and checks after each that no
group without a retained frame stays and that the table stays bounded. It
fails with the trim removed.
@akosidencio
akosidencio marked this pull request as ready for review November 26, 2026 20:56
@akosidencio
akosidencio merged commit 4107f1e into dev Nov 26, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant