From fb6b3a049cc031e648e63fbc85974cccc093525f Mon Sep 17 00:00:00 2001 From: Atsika Date: Sat, 15 Aug 2026 18:49:21 +0200 Subject: [PATCH] Shrink the receive read buffer from 16 MB to 64 KiB The 16 MB read buffer dates from before record reassembly existed, when a read had to swallow a whole record or lose its tail. ReceiveLoop now accumulates across reads, so the read size only decides how many iterations a large payload takes; framing is unaffected at any size, which the reassembly test asserts down to a single byte per read. aznet's Read handles a caller buffer smaller than a frame by returning a partial copy and draining the remainder on the next call, so a small buffer costs extra copies, not correctness. The allocation is per handler, so the proxy was reserving 16 MB per connected agent, and the agent 16 MB for one transport. --- pkg/protocol/base.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/protocol/base.go b/pkg/protocol/base.go index afc6417..70b263b 100644 --- a/pkg/protocol/base.go +++ b/pkg/protocol/base.go @@ -119,7 +119,9 @@ func (h *BaseHandler) ReceiveLoop() { // records back to back, or a whole record plus the head of the next one. // The accumulator below therefore lives OUTSIDE the read loop so that a // record straddling two Read calls is reassembled rather than discarded. - buffer := make([]byte, 16*1024*1024) + // The read size only bounds how many iterations a large payload takes, never + // how it is framed, so it costs nothing to keep it small. + buffer := make([]byte, 64*1024) acc := make([]byte, 0, HeaderSize+MaxPacketDataSize) for {