Skip to content

protozero: let tokenized messages outlive the read loop - #7275

Draft
LalitMaganti wants to merge 1 commit into
dev/lalitm/zerocopy-5-traceblob-adoptfrom
dev/lalitm/zerocopy-6-owned-messages
Draft

protozero: let tokenized messages outlive the read loop#7275
LalitMaganti wants to merge 1 commit into
dev/lalitm/zerocopy-5-traceblob-adoptfrom
dev/lalitm/zerocopy-6-owned-messages

Conversation

@LalitMaganti

@LalitMaganti LalitMaganti commented Aug 28, 2026

Copy link
Copy Markdown
Member

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.*'

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

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
LalitMaganti force-pushed the dev/lalitm/zerocopy-6-owned-messages branch from e04db79 to 71c441d Compare August 28, 2026 15:10
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