feat: add zero-copy connection support #3642
Open
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 the ability to use zero-copy connections with QUIC.
Internally, the package already uses a pull based model for reading packets. It first gets a byte slice from a buffer pool, then it reads into this slice using the
ReadFrom
method. This read then returns areceivedPacket
structure which is processed accordingly.This PR allows for the creation of
receivedPacket
structures without using copy semantics originating fromReadFrom
andWriteTo
methods.It accomplishes this by allowing the use of a custom buffer pool per connection. QUIC can request a new buffer to be allocated, typically for writing. Each byte slice is accompanied by an
int
tag which uniquely identifies that buffer. When QUIC is done processing the slice, it will release the buffer from the pool. Custom buffer pools can use the tag to identify the state of such a buffer.Similarly, byte slices originating from a zero-copy
ReadPacket()
function should also originate from the same buffer pool and be tracked with tags.Thus, by using the byte slice tag you can coordinate zero-copy or asynchronous sends and receives. For example, you can use
io_uring
queues to send or read buffers; or eBPF urings for reading only, etc.(This is a WIP PR and I would love a discussion over it.)