Skip to content

Conversation

@dannykopping
Copy link

@dannykopping dannykopping commented Dec 12, 2025

Warning: vibe-coded!

Dependency of coder/coder#21251

I asked Opus 4.5 to justify its changes:

  1. IdealBatchSize: 128 → 4

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.


  1. QueueOutboundSize/InboundSize/HandshakeSize: 1024 → 64

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.


  1. MaxSegmentSize: 65535 → 2048

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:

Platform MaxSegmentSize
Default (Linux) 65535
Windows 2016 (2048-32)
iOS 1700
Android 2200
testsmallbuffers 2048

Critical insight: Windows and iOS run in production with values ≤2048. Our test value of 2048 is:

  • Equal to Windows production value
  • Larger than iOS production value (1700)
  • Larger than standard MTU (1500) + WireGuard overhead (~80 bytes)

Since iOS devices successfully run WireGuard in production with MaxSegmentSize=1700, our test value of 2048 is definitively safe.


  1. PreallocatedBuffersPerPool: 0 (unchanged)

Already 0 in default config, meaning sync.Pool handles allocation dynamically. No change needed.


Memory Calculation

Per-device with default settings:

  • Message buffers: ~65KB each, pooled
  • Container slices: 128 pointers × multiple pools

Per-device with testsmallbuffers:

  • Message buffers: ~2KB each, pooled
  • Container slices: 4 pointers × multiple pools

Result: ~32x reduction in per-buffer memory, compounding across hundreds of test connections.


Verdict

All changes are justified and safe:

  1. IdealBatchSize=4: Affects only throughput, not correctness
  2. Queue sizes=64: Provides backpressure, doesn't fail
  3. MaxSegmentSize=2048: Production-proven on Windows and iOS - this is the key insight that validates the choice

Signed-off-by: Danny Kopping <danny@coder.com>
Windows, Android, and iOS queueconstants files need to exclude
testsmallbuffers to avoid duplicate constant declarations when
building with -tags=testsmallbuffers.

Signed-off-by: Danny Kopping <danny@coder.com>
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