diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-26 23:44:37 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-27 01:48:58 +0100 |
commit | 8cc99631d025f5013e40f8a5a7b3370bff1c577e (patch) | |
tree | 0ac01dbe4785fc450b73054759f537f92f34a364 /device/peer.go | |
parent | d669c78c4306290963415568f4a64a1ae2b35b20 (diff) | |
download | wireguard-go-8cc99631d025f5013e40f8a5a7b3370bff1c577e.tar.gz wireguard-go-8cc99631d025f5013e40f8a5a7b3370bff1c577e.zip |
device: use linked list for per-peer allowed-ip traversal
This makes the IpcGet method much faster.
We also refactor the traversal API to use a callback so that we don't
need to allocate at all. Avoiding allocations we do self-masking on
insertion, which in turn means that split intermediate nodes require a
copy of the bits.
benchmark old ns/op new ns/op delta
BenchmarkUAPIGet-16 3243 2659 -18.01%
benchmark old allocs new allocs delta
BenchmarkUAPIGet-16 35 30 -14.29%
benchmark old bytes new bytes delta
BenchmarkUAPIGet-16 1218 737 -39.49%
This benchmark is good, though it's only for a pair of peers, each with
only one allowedips. As this grows, the delta expands considerably.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device/peer.go')
-rw-r--r-- | device/peer.go | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/device/peer.go b/device/peer.go index 5324ae4..a103b5d 100644 --- a/device/peer.go +++ b/device/peer.go @@ -28,6 +28,7 @@ type Peer struct { device *Device endpoint conn.Endpoint persistentKeepaliveInterval uint32 // accessed atomically + firstTrieEntry *trieEntry // These fields are accessed with atomic operations, which must be // 64-bit aligned even on 32-bit platforms. Go guarantees that an |