From b4db89ea9def1e851c67d90f493ce57f55c322ba Mon Sep 17 00:00:00 2001 From: cathugger Date: Mon, 30 Jul 2018 13:44:46 +0000 Subject: [PATCH] Avoid unnecessarily allocating coords slice if it's unchanged. --- src/yggdrasil/session.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index 0abf524..7a33226 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -4,7 +4,10 @@ package yggdrasil // It's responsible for keeping track of open sessions to other nodes // The session information consists of crypto keys and coords -import "time" +import ( + "bytes" + "time" +) // All the information we know about an active session. // This includes coords, permanent and ephemeral keys, handles and nonces, various sorts of timing information for timeout and maintenance, and some metadata for the admin API. @@ -72,8 +75,10 @@ func (s *sessionInfo) update(p *sessionPing) bool { if p.MTU >= 1280 || p.MTU == 0 { s.theirMTU = p.MTU } - // allocate enough space for additional coords - s.coords = append(make([]byte, 0, len(p.Coords)+11), p.Coords...) + if !bytes.Equal(s.coords, p.Coords) { + // allocate enough space for additional coords + s.coords = append(make([]byte, 0, len(p.Coords)+11), p.Coords...) + } now := time.Now() s.time = now s.tstamp = p.Tstamp