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

multiaddr: Replace Bytes with Arc<Vec<u8>>. #1370

Merged
merged 5 commits into from Jan 7, 2020

Conversation

twittner
Copy link
Contributor

@twittner twittner commented Jan 3, 2020

CC: #1367, #1351

@tomaka
Copy link
Member

tomaka commented Jan 3, 2020

What about Arc<[u8]> instead? This needs a bit more efforts, but we remove one indirection.

@burdges
Copy link

burdges commented Jan 4, 2020

Just curious: What's wrong with Bytes? I forgotten it but vaguely recall it attempting to do some things nicely.

@twittner
Copy link
Contributor Author

twittner commented Jan 6, 2020

What about Arc<[u8]> instead? This needs a bit more efforts, but we remove one indirection.

I think that resizing complicates this approach. It would probably require quite a bit of effort to reach the same level of efficiency as with Bytes or Arc<Vec<u8>>. If we do not want to pay for the Vec<u8> allocation, maybe it is best to keep the current bytes v0.4 implementation?

Just curious: What's wrong with Bytes? I forgotten it but vaguely recall it attempting to do some things nicely.

Compared to previous versions, in v0.5 the design of Bytes lends itself more strongly to immutable usage. In particular Bytes::try_mut has been removed and we made use of it to efficiently modify Multiaddr values which are not shared.

Copy link
Member

@tomaka tomaka left a comment

Choose a reason for hiding this comment

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

Small nit: I'm extremely paranoid when it comes to the Write trait.
Writing to a &mut Vec<u8> automatically extends the vector, while writing to a &mut [u8] will return an error if there isn't enough space.
Because of that, I'd prefer to make explicit that we're writing to a &mut Vec<u8>.

misc/multiaddr/src/lib.rs Outdated Show resolved Hide resolved
misc/multiaddr/src/lib.rs Outdated Show resolved Hide resolved
twittner and others added 2 commits January 6, 2020 15:25
Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>
@tomaka
Copy link
Member

tomaka commented Jan 6, 2020

Let's wait for #1328 before merging!

@mxinden
Copy link
Member

mxinden commented Jan 6, 2020

Do I understand correctly that we have the following 4 options that only differ in performance?

  • Keep using bytes 0.4.

  • Switch to bytes 0.5 having to clone a BytesMut.

  • Use Arc<Vec<u8>>.

  • Use Arc<[u8]>.

If so, before introducing this change set, shouldn't it include benchmarks? Am I missing something?

@twittner
Copy link
Contributor Author

twittner commented Jan 6, 2020

Do I understand correctly that we have the following 4 options that only differ in performance?

  • Keep using bytes 0.4.
  • Switch to bytes 0.5 having to clone a BytesMut.

This second option would not provide much benefit over a Vec<u8> as BytesMut will copy on clone.

  • Use Arc<Vec<u8>>.
  • Use Arc<[u8]>.

If so, before introducing this change set, shouldn't it include benchmarks? Am I missing something?

The last option has not been implemented. I welcome all benchmarks but the change is not really about improving the performance over what we have now but motivated by the desire to remove a now outdated dependency (bytes v0.4). In #1353 I left parity-multiaddr as is because I would be fine with keeping it as an implementation detail, but since #1351 is still open, there seems to be a need to get rid of it.

@tomaka tomaka changed the base branch from stable-futures to master January 7, 2020 09:21
@tomaka tomaka merged commit ab2eb7a into libp2p:master Jan 7, 2020
@twittner twittner deleted the rm-bytes-from-multiaddr branch January 7, 2020 14:06
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.

None yet

4 participants