tailscale/wgengine
Josh Bleecher Snyder 88586ec4a4 wgengine/magicsock: remove an alloc from ReceiveIPvN
We modified the standard net package to not allocate a *net.UDPAddr
during a call to (*net.UDPConn).ReadFromUDP if the caller's use
of the *net.UDPAddr does not cause it to escape.
That is https://golang.org/cl/291390.

This is the companion change to magicsock.
There are two changes required.
First, call ReadFromUDP instead of ReadFrom, if possible.
ReadFrom returns a net.Addr, which is an interface, which always allocates.
Second, reduce the lifetime of the returned *net.UDPAddr.
We do this by immediately converting it into a netaddr.IPPort.

We left the existing RebindingUDPConn.ReadFrom method in place,
as it is required to satisfy the net.PacketConn interface.

With the upstream change and both of these fixes in place,
we have removed one large allocation per packet received.

name           old time/op    new time/op    delta
ReceiveFrom-8    16.7µs ± 5%    16.4µs ± 8%     ~     (p=0.310 n=5+5)

name           old alloc/op   new alloc/op   delta
ReceiveFrom-8      112B ± 0%       64B ± 0%  -42.86%  (p=0.008 n=5+5)

name           old allocs/op  new allocs/op  delta
ReceiveFrom-8      3.00 ± 0%      2.00 ± 0%  -33.33%  (p=0.008 n=5+5)

Co-authored-by: Sonia Appasamy <sonia@tailscale.com>
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-02-12 09:52:43 -08:00
..
filter wgengine/filter: add a Clone method. 2021-01-22 17:31:37 -08:00
magicsock wgengine/magicsock: remove an alloc from ReceiveIPvN 2021-02-12 09:52:43 -08:00
monitor wgengine/monitor: close closeHandle 2021-01-07 20:18:02 -08:00
netstack types/netmap: split controlclient.NetworkMap off into its own leaf package 2021-02-05 16:18:52 -08:00
router wgengine/router: fix BSD router to support multiple local addrs, IPv6 2021-02-11 19:13:03 -08:00
tsdns tstest: simplify goroutine leak tests 2021-02-03 13:06:40 -08:00
tstun wgengine/tstun: reply to MagicDNS pings 2021-02-11 11:55:38 -08:00
wgcfg types/netmap: split controlclient.NetworkMap off into its own leaf package 2021-02-05 16:18:52 -08:00
wglog wgengine: adapt to wireguard-go changes 2021-02-04 15:15:33 -08:00
winnet wgengine/winnet: don't build on non-windows 2021-02-09 21:09:24 -08:00
pendopen.go ipn: split LocalBackend off into new ipn/ipnlocal package 2021-02-04 14:04:23 -08:00
userspace_test.go all: move wgcfg from wireguard-go 2021-01-29 12:52:56 -08:00
userspace.go wgengine: remove IpcGetOperation filter 2021-02-08 20:22:55 -08:00
watchdog_test.go cmd/tailscaled, wgengine/netstack: add start of gvisor userspace netstack work 2021-01-11 09:31:14 -08:00
watchdog.go types/netmap: split controlclient.NetworkMap off into its own leaf package 2021-02-05 16:18:52 -08:00
wgengine.go types/netmap: split controlclient.NetworkMap off into its own leaf package 2021-02-05 16:18:52 -08:00