Repository navigation
Conversation
resetius
force-pushed
the
read-buffer-common
branch
from
November 15, 2026 21:40
5a65a42 to
b6ccea4
Compare
This was referenced Nov 15, 2026
resetius
marked this pull request as ready for review
November 15, 2026 22:40
resetius
marked this pull request as draft
November 15, 2026 23:25
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.
Adds
co_await handle.ReadBuffer(): a read into a buffer of the poller instead of the caller's memory. This is step 1 of 3 of the design approved in the tracker (multishot reads on TUring need the backend to own the buffer).API (additive, nothing existing changes):
TReadBuffer: move-only lease.Data()gives the bytes not consumed,Consume(n)drops the first n, the destructor gives the buffer back. An empty lease is the end of the stream; errors throwstd::system_error.TPollerBase::ConfigureReadBuffers(TReadBufferConfig):BufferSize16 KiB,Count1024,PerSocketLimit8 (used by the read-ahead pollers in the next PRs). Memory is allocated at the firstReadBuffer(), pages are touched only when used.ReadBuffer()onTSocket/TFileHandleand on the poller-driven handles.This PR has one implementation for every backend:
ReadSome()of the handle into a buffer acquired from the pool, waiting again after a spurious wake-up. TUring and TIOCp use it too for now. The next PRs, stacked on this one, add the read-ahead: multishot recv/read into a buffer ring on TUring, one WSARecv per socket on IOCP.ReadSome()is not touched on any backend: no new branch, no lookup, no allocation. Only a poller that reads ahead has a queue of leases, so theReadSome()adapter over that queue comes with the TUring PR. HereReadSome()afterReadBuffer()simply reads the next bytes, so the order is kept by construction.Reuse of existing primitives
TArena: the free-list core ofTArenaAllocator, moved into a non-template class with a runtime slot size and an optional limit on pools.TArenaAllocator<T, PoolSize>is now a thin wrapper over it, with the same interface and behaviour;Allocate()gets one compare, only when the free list is empty.Countslots, so a buffer also has an index (Slot(i),Index(p)). The uring buffer ring needs that: one region, addressed by the 16-bit buffer id in the CQE.TZeroCopyLineSplitterandTZeroCopyEnvelopeReader(V2), and Release ofTPodAllocator:Acquire(lease)gives the span to read into,Commit(lease, n)publishes the bytes read (Commit(id, n)for a buffer the kernel picked),Release(id)gives a buffer back. The consumer side isData()/Consume(n).TZeroCopyEnvelopeReaderV2are separate 1 MiB allocations with one writer each, not one region with ids.TPodAllocatoris plainnew/deletefor variable-size blobs.TArenaof 1 MiB slots. Its blobs would need a refcounted lease, and read-ahead into such big buffers would needIOU_PBUF_RING_INC.Details:
ReadBuffer()throwsstd::errc::no_buffer_space.ReadSome(),ReadBuffer()tries the read first on the readiness pollers.Tests (all pollers of each platform): end of stream, read error (RST),
Consume()and moves, order when mixingReadSome()andReadBuffer(), all buffers leased plus a 256 KiB transfer through 2 buffers, close while a reader waits, reader destroyed while waiting, pipes and regular files.Regression check of plain
ReadSome(), master 85489f0 vs this PR b6ccea4, Release.examples/bench -n 1024 -w 100000, single, 25 runs per invocation. Median of the per-run p50 over alternating repetitions, min-max in brackets.perf statcycles:u+cycles:k of-w 100000minus-w 100, per hop.taskset -c 3. Mac: Apple M5 Pro, macOS 26.6, Apple clang 21.Actor bench (
ping_actors, 10 nodes, inflight 1024, 10M messages), msg/s, median of 7:The +6% on the epoll actor bench came with the
TArenachange; the first version of this PR, without it, gave 818k vs 824k. It is likely memory layout, not a real speed-up.