Skip to content

perf: improve Bytes::copy_to_bytes#688

Merged
Darksonn merged 1 commit intotokio-rs:masterfrom
tisonkun:perf-copy-to-bytes-bytes
Apr 10, 2024
Merged

perf: improve Bytes::copy_to_bytes#688
Darksonn merged 1 commit intotokio-rs:masterfrom
tisonkun:perf-copy-to-bytes-bytes

Conversation

@tisonkun
Copy link
Copy Markdown
Contributor

@tisonkun tisonkun commented Apr 9, 2024

Ref - https://greptime.com/blogs/2024-04-09-rust-protobuf-performance#step-5-why-is-bytes-slice-so-slow

We already use this tech for BytesMut, but not bring it for Bytes. Namely, reduce the overhead of slice.

impl Buf for BytesMut {
    ...
    fn copy_to_bytes(&mut self, len: usize) -> Bytes {
        self.split_to(len).freeze()
    }
}

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun force-pushed the perf-copy-to-bytes-bytes branch from cd1401c to a1849ab Compare April 9, 2024 23:49
@tisonkun
Copy link
Copy Markdown
Contributor Author

tisonkun commented Apr 9, 2024

cc @Darksonn

Copy link
Copy Markdown
Contributor

@braddunbar braddunbar left a comment

Choose a reason for hiding this comment

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

Nice! Great consolidation.

@tisonkun
Copy link
Copy Markdown
Contributor Author

@braddunbar shall we merge this patch? Or it's still wait for further reviews?

@Darksonn Darksonn merged commit b5fbfc3 into tokio-rs:master Apr 10, 2024
@tisonkun tisonkun deleted the perf-copy-to-bytes-bytes branch April 10, 2024 14:59
@tisonkun
Copy link
Copy Markdown
Contributor Author

Thank you!

@Darksonn
Copy link
Copy Markdown
Member

Thank you for the PR :)

@mox692 mox692 mentioned this pull request Jul 30, 2024
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.

3 participants