From 56f5c749e180323be062975eed7bc01d407feda3 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 8 Apr 2015 21:54:45 +0100 Subject: [PATCH] optimise broadcast route calculation ...by obtaining our connection set just once. This also guards against potential locking issues, since we no longer obtain the required lock on our local peer while holding a lock on Peers. Note that this change means the connection list can be out of date by the time we enter Peers.ForEach. However, previously it was possible for the list to change for each peer we are iterating over. So it's just a different flavour of out-of-dateness. --- router/routes.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/router/routes.go b/router/routes.go index df2b890a..3da3d1f2 100644 --- a/router/routes.go +++ b/router/routes.go @@ -180,6 +180,7 @@ func (routes *Routes) calculateUnicast(establishedAndSymmetric bool) map[PeerNam func (routes *Routes) calculateBroadcast(establishedAndSymmetric bool) map[PeerName][]PeerName { broadcast := make(map[PeerName][]PeerName) ourself := routes.ourself + ourConnections := ourself.Connections() routes.peers.ForEach(func(peer *Peer) { hops := []PeerName{} @@ -187,7 +188,7 @@ func (routes *Routes) calculateBroadcast(establishedAndSymmetric bool) map[PeerN // This is rather similar to the inner loop on // peer.Routes(...); the main difference is in the // locking. - for conn := range ourself.Connections() { + for conn := range ourConnections { if establishedAndSymmetric && !conn.Established() { continue }