Repository navigation
Perf: Introduce zero copy path when tonic returns an aligned buffer - #10273
Conversation
|
@Jefffrey can you take a look at this? Thank you |
|
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 |
|
👀 |
|
thanks @Rich-T-kid, nice improvement |
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