Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Multiaddr a newtype of []bytes #63

Closed
wants to merge 2 commits into from
Closed

Conversation

Stebalien
Copy link
Member

@Stebalien Stebalien commented Dec 16, 2017

This allows us to send multiaddrs on the wire without copying (through the Bytes() method). It also avoids one allocation/indirection per multiaddr.

This is an alternative (or stop-gap) to #62 as #62 is invasive. Unlike #62, this PR doesn't break Multiaddr == nil or maddr1.Equals(maddr2). However, it doesn't allow multiaddrs to be used as map keys :(.

Motivation: Make the allocate less when reporting closer peers. That's currently one of our largest sources of ephemeral byte slice allocations.

This allows us to send multiaddrs on the wire without copying (through the
`Bytes()` method). It also avoids one allocation/indirection per multiaddr.

This is an alternative (or stop-gap) to #62 as #62 is invasive. Unlike #62, this
PR doesn't break `Multiaddr == nil` or `maddr1.Equals(maddr2)`. However,
it *doesn't* allow multiaddrs to be used as map keys :(.
@@ -215,12 +215,6 @@ func TestBytesSplitAndJoin(t *testing.T) {
t.Errorf("joined components failed: %s != %s", m, joined)
}

// modifying underlying bytes is fine.
m2 := m.(*multiaddr)
for i := range m2.bytes {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could change this to just directly modify m2. I think the check is still valuable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is actually broken, that's why I removed it. I'm no longer copying on Split, just slicing. I'm now assuming that multiaddrs are immutable. I'm not entirely sure why we had this test in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants