Skip to content

Reduce allocation in `QueuePacketConn.WriteTo`

Like with #40187 (closed), this is safe to do and more efficient when the caller does not reuse the passed-in buffer. In kcp-go, WriteTo is called inside UDPSession.defaultTx via UDPSession.tx from UDPSession.uncork, which immediately discards the buffers it has just written (s.txqueue = s.txqueue[:0]).

UDPSession.defaultTx is the largest single allocator of temporary memory in the memory profile of #40086 (comment 2838372).