Skip to content

consomme/tcp: use memcpy for ring buffer payload copy#2886

Open
benhillis wants to merge 1 commit intomicrosoft:mainfrom
benhillis:consomme_memcpy
Open

consomme/tcp: use memcpy for ring buffer payload copy#2886
benhillis wants to merge 1 commit intomicrosoft:mainfrom
benhillis:consomme_memcpy

Conversation

@benhillis
Copy link
Member

Replace byte-by-byte iterator copy with copy_from_slice on the ring buffer's contiguous slices. This compiles to memcpy and avoids per-byte iterator overhead when constructing outbound TCP packets.

Add View::copy_to_slice() to encapsulate the two-slice copy pattern and remove the now-unused View::iter() method.

Replace byte-by-byte iterator copy with copy_from_slice on the
ring buffer's contiguous slices. This compiles to memcpy and avoids
per-byte iterator overhead when constructing outbound TCP packets.

Add View::copy_to_slice() to encapsulate the two-slice copy pattern
and remove the now-unused View::iter() method.
@benhillis benhillis requested a review from jstarks March 5, 2026 00:05
@benhillis benhillis requested a review from a team as a code owner March 5, 2026 00:05
Copilot AI review requested due to automatic review settings March 5, 2026 00:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Optimizes Consommé’s TCP transmit path by replacing per-byte payload copying with slice-based copying that compiles down to memcpy, and centralizes the ring-buffer two-slice copy logic in View.

Changes:

  • Add View::copy_to_slice() to copy ring-buffer views into a destination buffer using copy_from_slice.
  • Remove the previous byte-by-byte iterator-based payload copy in tcp.rs and use copy_to_slice() instead.
  • Remove the now-unused View::iter() API (replaced by the new copy helper).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
vm/devices/net/net_consomme/consomme/src/tcp/ring.rs Replaces View::iter() with View::copy_to_slice() to enable efficient contiguous/two-slice copies.
vm/devices/net/net_consomme/consomme/src/tcp.rs Switches TCP payload construction from byte iteration to View::copy_to_slice() for better performance.

You can also share your feedback on Copilot code review. Take the survey.

@benhillis
Copy link
Member Author

I'm going to confirm the old code isn't being optimized to use memcpy already.

@benhillis
Copy link
Member Author

I'm going to confirm the old code isn't being optimized to use memcpy already.

I've confirmed that the previous code generated code that does not use memcpy, but this does.

@benhillis
Copy link
Member Author

Holding off on merging this for now until I can reason about some odd perf behavior we are seeing with this change.

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.

4 participants