Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(s2n-quic-core): add ReceiveBuffer::copy_into_buf #2052

Merged
merged 2 commits into from
Dec 2, 2023

Conversation

camshaft
Copy link
Contributor

@camshaft camshaft commented Nov 29, 2023

Description of changes:

For an application that needs to copy data out into, for example, a tokio::io::ReadBuf, the current ReceiveBuffer::pop interface is less than ideal. The way it is implemented, it assumes that the BytesMut will be passed around for copy-avoidance. Splitting bytes off from other chunks only to copy it and drop the new reference requires shared promotion and refcount increment/decrement.

This change, instead, provides a copy_into_buf function that avoids the split calls and instead uses BufMut::advance_mut, which avoids the previously-mentioned downsides.

Call-outs:

I updated the benchmarks to use the copy_into_buf function instead of pop to avoid oversampling on the pop, especially since the benchmarks just discard the received chunk.

Testing:

I've included a unit test showing it all working. Most of the implementation is shared with pop via the internal pop_transform method.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@camshaft camshaft marked this pull request as ready for review November 29, 2023 20:15
@camshaft camshaft merged commit 665b3e3 into main Dec 2, 2023
@camshaft camshaft deleted the camshaft/buffer-copy-buf branch December 2, 2023 02:26
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.

2 participants