Rich-T-kid opened a new pull request, #10044: URL: https://github.com/apache/arrow-rs/pull/10044
# 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. --> - Closes #10029. [A document that provides a bit of context](https://github.com/user-attachments/files/28477762/Arrow.flight.speed.up.2.pdf) # Rationale for this change Compression is the most compute and memory intensive part of the arrow-ipc encoding pipeline. It runs per buffer, not per record batch. For a Flight stream of 10 batches with 5 primitive arrays each, that is 100 compression calls minimum, [more for string and struct arrays](https://arrow.apache.org/docs/format/Columnar.html#compression). Each of those calls produced an owned compressed Vec that was then copied a second time into a flat arrow_data accumulator before being written to the output. For the uncompressed path the situation was the same: Arc-backed buffer slices that required no compression were still copied into that accumulator unnecessarily. Separately, the original **write_message()** function flushed after every dictionary and every record batch, causing repeated small OS write calls per batch. The goal was to eliminate both problems: stop copying buffers that do not need to be copied, and stop flushing on every message. <!-- 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? <!-- 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. --> - Introduced EncodedBuffer, an enum that wraps either a raw Arc-backed Buffer for the uncompressed path or an owned Vec for the compressed path, so both can be held in a uniform collection without an extra copy into a flat accumulator - Changed write_array_data to push EncodedBuffer segments instead of copying bytes into arrow_data - Added write_batch_direct on IpcDataGenerator which writes the FlatBuffer metadata header first, then streams each EncodedBuffer segment directly to the writer with per-buffer alignment padding, never assembling an intermediate flat Vec for the body - FileWriter and StreamWriter both now call **write_batch_direct()**, eliminating the flush-per-message behavior and the intermediate copy on the hot path # Are these changes tested? These changes are intended to be completely seamless. I didn't write new unit test for the code as nothing externally changed. all test still pass <!-- 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. --> ## benchmarks [**main** -> `cargo bench --bench ipc_writer -- "StreamWriter/write_10$" --sample-size 100`] [**my branch** -> `cargo bench --bench ipc_writer -- "StreamWriter/write_10$" --sample-size 100` ] <img width="1832" height="982" alt="Image 6-1-26 at 3 19 PM" src="https://github.com/user-attachments/assets/8e6253a4-8a53-4d03-bdab-d0321edc2561" /> [**main** -> `cargo bench --bench ipc_writer -- --sample-size 1000`] [**my branch** -> `cargo bench --bench ipc_writer -- --sample-size 1000`] <img width="1944" height="1000" alt="Image 6-1-26 at 3 20 PM" src="https://github.com/user-attachments/assets/dc8015e8-ed60-487c-aa66-06f5d35499fe" /> # 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. --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
