Perf: Introduce zero copy path when tonic returns an aligned buffer#10273
Open
Rich-T-kid wants to merge 2 commits into
Open
Perf: Introduce zero copy path when tonic returns an aligned buffer#10273Rich-T-kid wants to merge 2 commits into
Rich-T-kid wants to merge 2 commits into
Conversation
Contributor
Author
|
@Jefffrey can you take a look at this? Thank you |
Contributor
|
run benchmark flight |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing rich-T-kid/avoid-copies-if-aligned (1af08d7) to d969025 (merge-base) diff File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
see #10206 (comment)
If the buffer Tonic returns happens to be 64-bit aligned (as the Arrow spec requires), we can wrap it directly via
Buffer::from(Bytes), a zero-copy path that just increments a reference count. If not,Buffer::from(&[u8])copies into a fresh aligned allocation. The check is cheap (a single pointer modulo), and can save a potentially very large buffer copy.What changes are included in this PR?
this PR adds a pointer check for the data body. if the buffer is aligned to a 64 bit address no copy happens, otherwise copy the bytes as usual.
Are these changes tested?
existing test cover this. if the buffer isn't aligned we fallback to copying it.
Are there any user-facing changes?
no