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

perf: improve Bytes::copy_to_bytes #688

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

tisonkun
Copy link
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
Copy link
Contributor Author

tisonkun commented Apr 9, 2024

cc @Darksonn

Copy link
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
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
15 checks passed
@tisonkun tisonkun deleted the perf-copy-to-bytes-bytes branch April 10, 2024 14:59
@tisonkun
Copy link
Contributor Author

Thank you!

@Darksonn
Copy link
Contributor

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