drpcstream: introduce shared BufferPool for ring buffer#55
Conversation
|
I had an idea which I ran through claude and below is the summary of it. I'm not planning to do it but in future we can re-consider if profiling shows any gain. Buffer pool: further optimization ideas Right now the data copy chain for an incoming message looks like this:
We could eliminate copy #2 by having the packet assembler get its buffer from the pool directly. The assembler already has a TODO for buffer reuse. Instead of reusing its own backing array across packets (lines 84-87), it would Another idea: size-bucketed pools (e.g. 1KiB, 16KiB, 32KiB) so that I think we should keep the pool simple for now. The assembler integration is the more interesting optimization since it removes a full copy per message. Worth revisiting once we have benchmarks to measure the actual impact. |
a17330d to
b91bf1b
Compare
cafa1dc to
b3d2355
Compare
b91bf1b to
a58986c
Compare
b3d2355 to
38c84dc
Compare
Add a BufferPool backed by sync.Pool that is shared across all streams within a Manager. The ring buffer now obtains buffers from the pool on Enqueue and transfers ownership to the caller on Dequeue, which advances the tail immediately. This removes the two-step Dequeue/Done protocol and simplifies Close (no longer needs to wait for held buffers). The pool is a required parameter in the Stream constructor, created once per Manager and passed to all streams it creates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
38c84dc to
f2f767f
Compare
Add a BufferPool backed by sync.Pool that is shared across all streams
within a Manager. The ring buffer now obtains buffers from the pool on
Enqueue and transfers ownership to the caller on Dequeue, which advances
the tail immediately. This removes the two-step Dequeue/Done protocol
and simplifies Close (no longer needs to wait for held buffers).
The pool is a required parameter in the Stream constructor, created once
per Manager and passed to all streams it creates.