Skip to content

perf(vmnetsock): batch stream input and join shutdown - #291

Merged
Code-Hex merged 3 commits into
mainfrom
codex/vmnetsock-packet-lifecycle
Oct 28, 2026
Merged

Code-Hex merged 3 commits into
mainfrom
codex/vmnetsock-packet-lifecycle

Conversation

@Code-Hex

Copy link
Copy Markdown
Owner

Why

The stream receive loop previously sent each frame through a separate vmnet.WritePacket call. It now groups complete frames already in the buffer and passes them to WritePackets. Only the first frame waits for input, so an incomplete following frame does not delay packets that are ready to send.

In a local QEMU/Linux guest comparison on macOS 27 with MTU 1500, median guest-to-host TCP throughput increased from 2.83 to 6.53 Gbit/s. Host-to-guest throughput stayed about the same, 7.87 to 7.88 Gbit/s. Each version ran three times with two-second transfers in each direction. The results describe this setup.

Changes

  • Borrow packet slices from a bounded stream buffer until the synchronous WritePackets call returns. This avoids a separate copy into each packet buffer. Keep complete frames ahead of malformed or truncated input.
  • Combine cancellation supervision and transfer completion into one goroutine. Close waits for both transfer loops, and no separate context watcher remains outside that wait. The adapter uses three goroutines instead of four.
  • Preserve the Dup and Close ownership rules. The caller owns duplicated descriptors, and the adapter borrows the interface without stopping it.
  • Release native network fixtures after each test. This prevents accumulated reservations from causing network creation failures before the later tests can run.

The regression tests cover incomplete input, valid frames before malformed input, cancellation, descriptor ownership, and shutdown under backpressure. Stream and Datagram guests completed boot, traffic, and shutdown, with descriptor and goroutine counts back at their starting values. UDP at 20,000 packets/s had no loss, duplicates, or reordering in the measured cases. Saturation traffic still dropped packets.

@Code-Hex
Code-Hex merged commit 8de084d into main Oct 28, 2026
13 checks passed
@Code-Hex
Code-Hex deleted the codex/vmnetsock-packet-lifecycle branch October 28, 2026 16:08
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