protozero: let tokenized messages outlive the read loop - #7275
Draft
LalitMaganti wants to merge 1 commit into
Draft
protozero: let tokenized messages outlive the read loop#7275LalitMaganti wants to merge 1 commit into
LalitMaganti wants to merge 1 commit into
Conversation
🎨 Perfetto UI Builds
|
ProtoRingBuffer hands out messages pointing into a buffer that the next
BeginWrite() is free to recompact or grow, so a message is only valid
until the following read. Passing one to another thread - what running
trace processor's RPC off the frontend thread needs - is therefore not
expressible, and the fallback is copying every request out, including
32 MB APPEND_TRACE_DATA chunks.
Refcount the buffer and hand out messages as slices holding a reference.
The write path is unchanged - a single non-wrapping buffer, rewound
whenever the read cursor catches up - except that recompacting, growing
and rewinding are now only allowed while nothing points into the buffer.
When something does, the write moves onto another buffer and the last
message releases the old one.
The buffer left behind is picked up again by the following switch, so a
caller retaining one message per write ping-pongs between two buffers
rather than allocating on each. Measured over 2000 messages, buffers
allocated:
msg size retained before after
512B 0 1 1
512B 1 8 2
512B 64 8 2
64K 1 2000 2
64K 64 2000 2000
The last row is a pool deep enough to pin every buffer at once, where
the allocations are the working set rather than waste.
out/linux_clang_release/perfetto_benchmarks \
--benchmark_filter='BM_ProtoRingBuffer.*'
LalitMaganti
force-pushed
the
dev/lalitm/zerocopy-6-owned-messages
branch
from
August 28, 2026 15:10
e04db79 to
71c441d
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.
ProtoRingBuffer hands out messages pointing into a buffer that the next
BeginWrite() is free to recompact or grow, so a message is only valid
until the following read. Passing one to another thread - what running
trace processor's RPC off the frontend thread needs - is therefore not
expressible, and the fallback is copying every request out, including
32 MB APPEND_TRACE_DATA chunks.
Refcount the buffer and hand out messages as slices holding a reference.
The write path is unchanged - a single non-wrapping buffer, rewound
whenever the read cursor catches up - except that recompacting, growing
and rewinding are now only allowed while nothing points into the buffer.
When something does, the write moves onto another buffer and the last
message releases the old one.
The buffer left behind is picked up again by the following switch, so a
caller retaining one message per write ping-pongs between two buffers
rather than allocating on each. Measured over 2000 messages, buffers
allocated:
msg size retained before after
512B 0 1 1
512B 1 8 2
512B 64 8 2
64K 1 2000 2
64K 64 2000 2000
The last row is a pool deep enough to pin every buffer at once, where
the allocations are the working set rather than waste.
out/linux_clang_release/perfetto_benchmarks
--benchmark_filter='BM_ProtoRingBuffer.*'