From 114d90bec898c61d3c64eba6c55b85fdb046d276 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 12 Mar 2016 01:04:27 -0500 Subject: [PATCH 1/2] don't reallocate on recvMsgPacket --- connection.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/connection.go b/connection.go index 923a6328..5ef77f7d 100644 --- a/connection.go +++ b/connection.go @@ -18,7 +18,7 @@ import ( const ( numBatchMsgPackets = 10 minReadBufferSize = 1024 - minWriteBufferSize = 1024 + minWriteBufferSize = 65536 idleTimeoutMinutes = 5 updateStatsSeconds = 2 pingTimeoutSeconds = 40 @@ -634,7 +634,11 @@ func (ch *Channel) recvMsgPacket(packet msgPacket) ([]byte, error) { ch.recving = append(ch.recving, packet.Bytes...) if packet.EOF == byte(0x01) { msgBytes := ch.recving - ch.recving = make([]byte, 0, defaultRecvBufferCapacity) + // clear the slice without re-allocating. + // http://stackoverflow.com/questions/16971741/how-do-you-clear-a-slice-in-go + // suggests this could be a memory leak, but we might as well keep the memory for the channel until it closes, + // at which point the recving slice stops being used and should be garbage collected + ch.recving = ch.recving[:0] // make([]byte, 0, ch.desc.RecvBufferCapacity) return msgBytes, nil } return nil, nil From 69c7ae5e3fd5fb9a3bf26d4b93f9ea8d6b921b44 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 12 Mar 2016 13:05:28 -0500 Subject: [PATCH 2/2] version bump --- version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.go b/version.go index 335843c9..d4a712f0 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package p2p -const Version = "0.3.1" // configurable params +const Version = "0.3.2" // memory optimizations