fix: use small buffers to make tests more efficient #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Warning: vibe-coded!
Dependency of coder/coder#21251
I asked Opus 4.5 to justify its changes:
What it controls: Number of packets handled per read/write batch operation.
Memory impact: This affects container pool allocations - each container holds BatchSize() element pointers. With 128, you get slices of 128 pointers; with 4, just 4 pointers.
Safety: ✅ Safe. If more than 4 packets need to be processed, wireguard simply does multiple batch operations. This only affects throughput, not correctness. Tests don't need high throughput.
What they control: Channel buffer sizes for packet queues.
Safety: ✅ Safe. If queues fill up, backpressure applies (blocks until space available). Tests don't generate sustained high packet rates. 64 is still a generous buffer for test scenarios.
What it controls: Maximum UDP datagram size. This is the size of [MaxMessageSize]byte arrays allocated for packet buffers.
Memory impact: This is the dominant factor. Each message buffer is MaxSegmentSize bytes. With 65535 bytes each, these quickly consume gigabytes across many connections.
Safety: ✅ Safe - and here's why:
Critical insight: Windows and iOS run in production with values ≤2048. Our test value of 2048 is:
Since iOS devices successfully run WireGuard in production with MaxSegmentSize=1700, our test value of 2048 is definitively safe.
Already 0 in default config, meaning sync.Pool handles allocation dynamically. No change needed.
Memory Calculation
Per-device with default settings:
Per-device with testsmallbuffers:
Result: ~32x reduction in per-buffer memory, compounding across hundreds of test connections.
Verdict
All changes are justified and safe: