perf(p2p): pass received payloads as Bytes instead of copying into Vec - #1393
Open
mattsse wants to merge 1 commit into
Open
perf(p2p): pass received payloads as Bytes instead of copying into Vec#1393mattsse wants to merge 1 commit into
mattsse wants to merge 1 commit into
Conversation
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.
mattsse
requested review from
0xKitsune,
0xrusowsky,
adityapk00,
klkvr and
legion2002
as code owners
September 3, 2026 22:07
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.
Commonware hands the receive path an
IoBufbacked by a pooled or aligned buffer.From<IoBuf> for Vec<u8>copies that buffer whileFrom<IoBuf> for Bytesshares 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,
BackfillResponseand the backfill response frame now carrybytes::Bytes, and the frame decoder slices the block out of the received buffer. The wire format is unchanged. ABytesbuilt 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.