mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 14:57:49 +00:00
wgengine: don't re-allocate trimmedNodes map (#5825)
Change-Id: I512945b662ba952c47309d3bf8a1b243e05a4736 Signed-off-by: Andrew Dunham <andrew@tailscale.com>
This commit is contained in:
parent
445c8a4671
commit
e5636997c5
@ -321,6 +321,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
golang.org/x/crypto/salsa20/salsa from golang.org/x/crypto/nacl/box+
|
||||
LD golang.org/x/crypto/ssh from tailscale.com/ssh/tailssh+
|
||||
golang.org/x/exp/constraints from golang.org/x/exp/slices
|
||||
golang.org/x/exp/maps from tailscale.com/wgengine
|
||||
golang.org/x/exp/slices from tailscale.com/ipn/ipnlocal+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/genetlink+
|
||||
golang.org/x/net/dns/dnsmessage from net+
|
||||
|
@ -18,6 +18,7 @@
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.zx2c4.com/wireguard/device"
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
"tailscale.com/control/controlclient"
|
||||
@ -671,7 +672,13 @@ func (e *userspaceEngine) maybeReconfigWireguardLocked(discoChanged map[key.Node
|
||||
trackNodes := make([]key.NodePublic, 0, len(full.Peers))
|
||||
trackIPs := make([]netip.Addr, 0, len(full.Peers))
|
||||
|
||||
trimmedNodes := map[key.NodePublic]bool{} // TODO: don't re-alloc this map each time
|
||||
// Don't re-alloc the map; the Go compiler optimizes map clears as of
|
||||
// Go 1.11, so we can re-use the existing + allocated map.
|
||||
if e.trimmedNodes != nil {
|
||||
maps.Clear(e.trimmedNodes)
|
||||
} else {
|
||||
e.trimmedNodes = make(map[key.NodePublic]bool)
|
||||
}
|
||||
|
||||
needRemoveStep := false
|
||||
for i := range full.Peers {
|
||||
@ -696,7 +703,7 @@ func (e *userspaceEngine) maybeReconfigWireguardLocked(discoChanged map[key.Node
|
||||
needRemoveStep = true
|
||||
}
|
||||
} else {
|
||||
trimmedNodes[nk] = true
|
||||
e.trimmedNodes[nk] = true
|
||||
}
|
||||
}
|
||||
e.lastNMinPeers = len(min.Peers)
|
||||
@ -706,12 +713,10 @@ func (e *userspaceEngine) maybeReconfigWireguardLocked(discoChanged map[key.Node
|
||||
TrimmedNodes map[key.NodePublic]bool
|
||||
TrackNodes []key.NodePublic
|
||||
TrackIPs []netip.Addr
|
||||
}{&min, trimmedNodes, trackNodes, trackIPs}); !changed {
|
||||
}{&min, e.trimmedNodes, trackNodes, trackIPs}); !changed {
|
||||
return nil
|
||||
}
|
||||
|
||||
e.trimmedNodes = trimmedNodes
|
||||
|
||||
e.updateActivityMapsLocked(trackNodes, trackIPs)
|
||||
|
||||
if needRemoveStep {
|
||||
|
Loading…
x
Reference in New Issue
Block a user