Commit f3c5dc5
authored
Perf: Introduce zero copy path when tonic returns an aligned buffer (#10273)
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->
- works towards #10125
# Rationale for this change
see
#10206 (comment)
If the buffer Tonic returns happens to be 64-bit aligned ([as the Arrow
spec
requires](https://arrow.apache.org/docs/format/Columnar.html#buffer-alignment-and-padding)),
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.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
# 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.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
# Are these changes tested?
existing test cover this. if the buffer isn't aligned we fallback to
copying it.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
If this PR claims a performance improvement, please include evidence
such as benchmark results.
-->
# Are there any user-facing changes?
no
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->1 parent 6035e28 commit f3c5dc5
1 file changed
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
339 | 348 | | |
340 | | - | |
| 349 | + | |
341 | 350 | | |
342 | 351 | | |
343 | 352 | | |
| |||
0 commit comments