mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-03 02:21:58 +00:00
tailcfg: optimize keyMarshalText
This function accounted for ~1% of all allocs by tailscaled. It is trivial to improve, so may as well. name old time/op new time/op delta KeyMarshalText-8 197ns ± 0% 47ns ± 0% -76.12% (p=0.016 n=4+5) name old alloc/op new alloc/op delta KeyMarshalText-8 200B ± 0% 80B ± 0% -60.00% (p=0.008 n=5+5) name old allocs/op new allocs/op delta KeyMarshalText-8 5.00 ± 0% 1.00 ± 0% -80.00% (p=0.008 n=5+5) Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
committed by
Josh Bleecher Snyder
parent
5190435d6e
commit
ceb568202b
@@ -518,3 +518,13 @@ func TestEndpointTypeMarshal(t *testing.T) {
|
||||
t.Errorf("got %s; want %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
var sinkBytes []byte
|
||||
|
||||
func BenchmarkKeyMarshalText(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
var k [32]byte
|
||||
for i := 0; i < b.N; i++ {
|
||||
sinkBytes = keyMarshalText("prefix", k)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user