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(udp): return borrowed Datagram on receive #2188

Merged
merged 2 commits into from
Oct 21, 2024

Conversation

mxinden
Copy link
Collaborator

@mxinden mxinden commented Oct 17, 2024

Stacked on top of #2187 which is stacked on top of #2184.

Previously recv_inner would return Datagram<Vec<u8>>. In other words, it would allocate a new Vec<u8> for each UDP datagram payload.

Now recv_inner reads into a provided buffer and returns Datagram<&[u8]>, i.e. it returns a view into the provided buffer without allocating.


Extracted out of #2093.

Part of #1693.

Pull request stack:

  1. feat: don't allocate in UDP recv path #2184
  2. feat(transport): accept borrowed instead of owned input datagram #2187
  3. (this one) feat(udp): return borrowed Datagram on receive #2188
  4. feat(bin): don't allocate in UDP recv path #2189

neqo-bin/src/udp.rs Outdated Show resolved Hide resolved
@mxinden mxinden marked this pull request as ready for review October 17, 2024 15:42
Copy link
Member

@martinthomson martinthomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer to @larseggert on this part. As far as I can see, it's good.

neqo-udp/src/lib.rs Show resolved Hide resolved
Previously `recv_inner` would return `Datagram<Vec<u8>>`. In other words, it
would allocate a new `Vec<u8>` for each UDP datagram payload.

Now `recv_inner` reads into a provided buffer and returns `Datagram<&[u8]>`,
i.e. it returns a view into the provided buffer without allocating.
Pass a long lived receive buffer to `neqo_udp::recv_inner`, receiving an
iterator of `Datagram<&[u8]>`s pointing into that buffer, thus no longer
allocating in UDP receive path.
@larseggert larseggert merged commit cc8e432 into recv-no-alloc-transport Oct 21, 2024
@larseggert larseggert deleted the recv-no-alloc-udp branch October 21, 2024 08:31
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.

3 participants