Skip to content

Commit 9b7a562

Browse files
authored
Merge pull request #5 from coder/testsmallbuffers-batch
fix: use smaller batch sizes under build tag for more efficient tests
2 parents 769cdd7 + f1923d2 commit 9b7a562

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

conn/batchsize_default.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build !testsmallbatch
2+
3+
/* SPDX-License-Identifier: MIT
4+
*
5+
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
6+
*/
7+
8+
package conn
9+
10+
const (
11+
IdealBatchSize = 128 // maximum number of packets handled per read and write
12+
)

conn/batchsize_testsmall.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build testsmallbatch
2+
3+
/* SPDX-License-Identifier: MIT
4+
*
5+
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
6+
*
7+
* Modified by Coder for test environments to reduce memory usage.
8+
*/
9+
10+
package conn
11+
12+
// IdealBatchSize is reduced for tests to minimize memory usage.
13+
// In production, this is 128 (see batchsize_default.go), but tests don't need
14+
// the full batch capacity and this significantly reduces memory overhead
15+
// from wireguard buffer pools (~8MB per connection down to ~256KB).
16+
const IdealBatchSize = 4

conn/conn.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
"strings"
1616
)
1717

18-
const (
19-
IdealBatchSize = 128 // maximum number of packets handled per read and write
20-
)
21-
2218
// A ReceiveFunc receives at least one packet from the network and writes them
2319
// into packets. On a successful read it returns the number of elements of
2420
// sizes, packets, and endpoints that should be evaluated. Some elements of

0 commit comments

Comments
 (0)