mirror of
https://git.zx2c4.com/wireguard-go
synced 2025-09-18 20:57:50 +02:00
Reduce allocations by eliminating byte reader, hand-rolled decoding and reusing message structs. Synthetic benchmark: var msgSink MessageInitiation func BenchmarkMessageInitiationUnmarshal(b *testing.B) { packet := make([]byte, MessageInitiationSize) reader := bytes.NewReader(packet) err := binary.Read(reader, binary.LittleEndian, &msgSink) if err != nil { b.Fatal(err) } b.Run("binary.Read", func(b *testing.B) { b.ReportAllocs() for range b.N { reader := bytes.NewReader(packet) _ = binary.Read(reader, binary.LittleEndian, &msgSink) } }) b.Run("unmarshal", func(b *testing.B) { b.ReportAllocs() for range b.N { _ = msgSink.unmarshal(packet) } }) } Results: │ - │ │ sec/op │ MessageInitiationUnmarshal/binary.Read-8 1.508µ ± 2% MessageInitiationUnmarshal/unmarshal-8 12.66n ± 2% │ - │ │ B/op │ MessageInitiationUnmarshal/binary.Read-8 208.0 ± 0% MessageInitiationUnmarshal/unmarshal-8 0.000 ± 0% │ - │ │ allocs/op │ MessageInitiationUnmarshal/binary.Read-8 2.000 ± 0% MessageInitiationUnmarshal/unmarshal-8 0.000 ± 0% Signed-off-by: Alexander Yastrebov <yastrebov.alex@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> |
||
---|---|---|
.. | ||
allowedips_rand_test.go | ||
allowedips_test.go | ||
allowedips.go | ||
bind_test.go | ||
channels.go | ||
constants.go | ||
cookie_test.go | ||
cookie.go | ||
device_test.go | ||
device.go | ||
devicestate_string.go | ||
endpoint_test.go | ||
indextable.go | ||
ip.go | ||
kdf_test.go | ||
keypair.go | ||
logger.go | ||
mobilequirks.go | ||
noise_test.go | ||
noise-helpers.go | ||
noise-protocol.go | ||
noise-types.go | ||
peer.go | ||
pools_test.go | ||
pools.go | ||
queueconstants_android.go | ||
queueconstants_default.go | ||
queueconstants_ios.go | ||
queueconstants_windows.go | ||
race_disabled_test.go | ||
race_enabled_test.go | ||
receive.go | ||
send.go | ||
sticky_default.go | ||
sticky_linux.go | ||
timers.go | ||
tun.go | ||
uapi.go |