From 6362ccb0d26e3d8b7015fee600efc2a1f3ca871a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 20 Sep 2017 18:17:12 -0700 Subject: [PATCH 1/2] preallocate protocol slice This was showing up on CPU profiles as a significant source of repeated allocations. We don't really care about over allocation (don't keep these slices around) and should rarely have more than 8 protocols in a single address. --- multiaddr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiaddr.go b/multiaddr.go index 41c0d0b..7350ea6 100644 --- a/multiaddr.go +++ b/multiaddr.go @@ -78,7 +78,7 @@ func (m *multiaddr) Protocols() []Protocol { } }() - var ps []Protocol + ps := make([]Protocol, 0, 8) b := m.bytes for len(b) > 0 { code, n, err := ReadVarintCode(b) From d8140735524f7fbbc975848fbc345268c559843a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 20 Sep 2017 18:19:29 -0700 Subject: [PATCH 2/2] remove debugging code no point in slowing things down unnecessarily just for some debugging code. --- multiaddr.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/multiaddr.go b/multiaddr.go index 7350ea6..2ab437c 100644 --- a/multiaddr.go +++ b/multiaddr.go @@ -69,15 +69,6 @@ func (m *multiaddr) String() string { // Protocols returns the list of protocols this Multiaddr has. // will panic in case we access bytes incorrectly. func (m *multiaddr) Protocols() []Protocol { - - // panic handler, in case we try accessing bytes incorrectly. - defer func() { - if e := recover(); e != nil { - err := e.(error) - panic("Multiaddr.Protocols error: " + err.Error()) - } - }() - ps := make([]Protocol, 0, 8) b := m.bytes for len(b) > 0 {