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

feat(types/buffer): skip copying in to_bytes when NonContiguous contains a single Bytes #5388

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

ever0de
Copy link
Contributor

@ever0de ever0de commented Dec 4, 2024

Which issue does this PR close?

Closes #5385

Rationale for this change

The Buffer::to_bytes method currently performs unnecessary copying when the buffer is NonContiguous but contains only a single Bytes. This results in reduced performance due to redundant data duplication. By optimizing to_bytes to return the single Bytes directly without copying, we can improve the efficiency of buffer operations.

What changes are included in this PR?

  • Optimized the Buffer::to_bytes method to return the single Bytes directly when NonContiguous contains only one Bytes, avoiding unnecessary copying.

Are there any user-facing changes?

No user-facing changes. This optimization improves internal performance without altering the public API or behavior visible to users.

@ever0de ever0de requested a review from Xuanwo as a code owner December 4, 2024 07:22
Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thank you @ever0de for optimizing this!

@Xuanwo Xuanwo changed the title perf(types/buffer): skip copying in to_bytes when NonContiguous contains a single Bytes feat(types/buffer): skip copying in to_bytes when NonContiguous contains a single Bytes Dec 4, 2024
@ever0de
Copy link
Contributor Author

ever0de commented Dec 4, 2024

Would it be better to perform an upstream rebase and update the commit messages as well? (perf -> feat)

@Xuanwo
Copy link
Member

Xuanwo commented Dec 4, 2024

Would it be better to perform an upstream rebase and update the commit messages as well? (perf -> feat)

That's fine, we will squash all the commits. Thank you anyway!

@Xuanwo Xuanwo merged commit eaf6c18 into apache:main Dec 4, 2024
240 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new feature: Buffer::to_bytes can be optimized when there is only one Bytes
2 participants