Skip to content

perf(vmnetsock): batch datagram forwarding - #292

Merged
Code-Hex merged 1 commit into
mainfrom
codex/vmnetsock-datagram-batching
Oct 29, 2026
Merged

Code-Hex merged 1 commit into
mainfrom
codex/vmnetsock-datagram-batching

Conversation

@Code-Hex

Copy link
Copy Markdown
Owner

Why

vmnetsock.Datagram currently calls WritePacket for every datagram received from the peer. This change collects up to 32 queued datagrams and passes them to WritePackets together. It returns as soon as the socket has no more data, so a single packet does not wait for a full batch.

Both directions use public recvmsg and sendmsg calls inside RawConn callbacks. Each socket syscall still handles one datagram. Batching received packets reduces calls into vmnet. Each callback also holds Go's I/O lock across several packets.

In three local QEMU/HVF Linux guest runs on macOS 27.0.1 with MTU 1500, median guest-to-host TCP throughput rose from 3.19 to 5.76 Gbps. Host-to-guest throughput was 3.41 Gbps before and 3.43 Gbps after. These measurements cover one host and guest configuration.

Behavior

  • Preserve packet boundaries and forward valid packets before reporting an invalid trailing packet.
  • Keep the send position across EAGAIN waits to avoid duplicate packets.
  • On ENOBUFS, discard the unsent remainder of the batch and continue with the next batch.
  • Keep the existing Dup and Close ownership rules and shutdown path. The adapter adds no goroutines and never stops its borrowed interface.

Real-socket tests cover truncation, partial sends, read deadlines, and close. Native race tests cover cancellation, backpressure, and concurrent Dup and Close.

Related to #205.

@Code-Hex
Code-Hex merged commit 1f1ac93 into main Oct 29, 2026
12 of 13 checks passed
@Code-Hex
Code-Hex deleted the codex/vmnetsock-datagram-batching branch October 29, 2026 00:54
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.

1 participant