Skip to content

perf(p2p): pass received payloads as Bytes instead of copying into Vec - #1393

Open
mattsse wants to merge 1 commit into
mainfrom
mattsse/perf-p2p-bytes-payloads
Open

perf(p2p): pass received payloads as Bytes instead of copying into Vec#1393
mattsse wants to merge 1 commit into
mainfrom
mattsse/perf-p2p-bytes-payloads

Conversation

@mattsse

@mattsse mattsse commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Commonware hands the receive path an IoBuf backed by a pooled or aligned buffer. From<IoBuf> for Vec<u8> copies that buffer while From<IoBuf> for Bytes shares it, so every inbound block, transaction, settlement proposal and signature paid one full copy of its payload before the event was built, and backfill response frames copied the block a second time out of the frame.

The P2P event payloads, BackfillResponse and the backfill response frame now carry bytes::Bytes, and the frame decoder slices the block out of the received buffer. The wire format is unchanged. A Bytes built from a pooled buffer keeps that buffer checked out until the last handle drops; the pool falls back to a plain allocation when exhausted rather than blocking, and the node drops the received bytes right after decoding, so retention is bounded by the existing 128-slot event and response channels.

Measured with a throwaway release-mode harness: the removed copy costs 0.2 µs for an 8 KB block, 0.7 µs at 46 KB and 4.3 µs at 252 KB, per message. Split out of #1388, which keeps the decode-once change; this can land after #1392, which consumes the same settlement payloads.

Commonware hands the receive path an IoBuf backed by a pooled or aligned
buffer. Converting it into a Vec<u8> copies the buffer, while converting
into Bytes shares it, so every inbound block, transaction, settlement
proposal and signature paid one full copy of its payload before the event
was built, and backfill response frames copied the block a second time out
of the frame. The event and response payloads now carry Bytes, the frame
decoder slices the block out of the received buffer, and the follower's
pending block buffer holds the shared bytes. The wire format is unchanged.
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