]> Cypherpunks repositories - gostls13.git/commit
net: optimize ReadMsgUDPAddrPort
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 1 Nov 2021 19:44:43 +0000 (12:44 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 2 Nov 2021 03:54:24 +0000 (03:54 +0000)
commit3c61cb3dcd888fdef1c7456be144a1c4a44272a7
tree2704aa01ec7d9c2d7b680df2931d779b99294aa3
parentb0472aa990dfa9fb4ffe49b5af6f3d744d81ba6e
net: optimize ReadMsgUDPAddrPort

Instead of implementing ReadMsgUDPAddrPort in terms of ReadMsgUDP,
do it the other way around. This keeps the code minimal while
still avoiding allocs.

We could also rearrange ReadMsgUDP to be mid-stack inlined to avoid
allocating the *UDPAddr, but anyone who's trying to eliminate
allocs should use ReadMsgUDPAddrPort instead anyway,
because ReadMsgUDP will always allocate at least once (the IP slice).

name                       old time/op    new time/op    delta
ReadWriteMsgUDPAddrPort-8    5.26µs ± 3%    5.29µs ± 6%     ~     (p=0.429 n=12+13)

name                       old alloc/op   new alloc/op   delta
ReadWriteMsgUDPAddrPort-8      176B ± 0%      128B ± 0%  -27.27%  (p=0.000 n=15+15)

name                       old allocs/op  new allocs/op  delta
ReadWriteMsgUDPAddrPort-8      5.00 ± 0%      4.00 ± 0%  -20.00%  (p=0.000 n=15+15)

Change-Id: I15228cb4ec4f13f2f390407b6c62c44c228e7201
Reviewed-on: https://go-review.googlesource.com/c/go/+/360596
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/net/udpsock.go
src/net/udpsock_plan9.go
src/net/udpsock_posix.go