rok commented on code in PR #51270:
URL: https://github.com/apache/arrow/pull/51270#discussion_r4738746389
##########
cpp/src/arrow/dataset/file_base.cc:
##########
@@ -629,7 +629,7 @@ class TeeNode : public acero::MapNode,
return batch;
}
- Status WriteNextBatch(std::shared_ptr<RecordBatch> batch,
+ Status WriteNextBatch(const std::shared_ptr<RecordBatch>& batch,
Review Comment:
🤖 -> Same as `DatasetWritingSinkNodeConsumer::WriteNextBatch`:
`ProcessBatch` passes `std::move(record_batch)`, so keeping `batch` by value
and forwarding `std::move(batch)` to `WriteBatch` avoids the copy and lets
`batch.reset()` drop the last reference.
##########
cpp/src/arrow/dataset/file_base.cc:
##########
@@ -439,7 +439,7 @@ class DatasetWritingSinkNodeConsumer : public
acero::SinkNodeConsumer {
}
private:
- Status WriteNextBatch(std::shared_ptr<RecordBatch> batch,
+ Status WriteNextBatch(const std::shared_ptr<RecordBatch>& batch,
Review Comment:
🤖 -> This is an ownership sink: `Consume` passes `std::move(record_batch)`,
and `WriteBatch` takes `batch` by value so it can call `batch.reset()` right
after partitioning to release memory early. Keeping `batch` by value and
passing `std::move(batch)` to `WriteBatch` avoids the copy and preserves the
early release.
##########
cpp/src/arrow/csv/reader.cc:
##########
@@ -1024,7 +1024,7 @@ class AsyncThreadedTableReader
using BaseTableReader::BaseTableReader;
AsyncThreadedTableReader(io::IOContext io_context,
- std::shared_ptr<io::InputStream> input,
+ const std::shared_ptr<io::InputStream>& input,
Review Comment:
🤖 -> `BaseTableReader` (`ReaderMixin`) and `StreamingReaderImpl` take
`input` by value and move it into `input_`, and `TableReader::Make` /
`StreamingReader::Make{,Async}` already pass `std::move(input)`. Keeping
`input` by value and forwarding `std::move(input)` in
`AsyncThreadedTableReader`, `MakeTableReader`, and `MakeStreamingReader` keeps
the whole chain zero-copy.
##########
cpp/src/arrow/csv/reader.cc:
##########
@@ -195,7 +195,7 @@ class SerialBlockReader : public BlockReader {
static Iterator<CSVBlock> MakeIterator(
Iterator<std::shared_ptr<Buffer>> buffer_iterator,
std::unique_ptr<Chunker> chunker,
- std::shared_ptr<Buffer> first_buffer, int64_t skip_rows) {
+ const std::shared_ptr<Buffer>& first_buffer, int64_t skip_rows) {
Review Comment:
🤖 -> `BlockReader` takes `first_buffer` by value and moves it into `buffer_`
(and `CSVRowCounter` already passes `std::move(first_buffer)` to
`MakeAsyncIterator`). Keeping `first_buffer` by value and passing
`std::move(first_buffer)` into `std::make_shared` here and in
`SerialBlockReader::MakeAsyncIterator` /
`ThreadedBlockReader::MakeAsyncIterator` avoids the copy.
##########
cpp/src/arrow/compute/kernels/aggregate_basic.cc:
##########
@@ -316,7 +316,7 @@ struct ProductImpl : public ScalarAggregator {
using ProductType = typename TypeTraits<AccType>::CType;
using OutputType = typename TypeTraits<AccType>::ScalarType;
- explicit ProductImpl(std::shared_ptr<DataType> out_type,
+ explicit ProductImpl(const std::shared_ptr<DataType>& out_type,
Review Comment:
🤖 -> `ProductImpl` stores `out_type` by value, and member `out_type` is
declared before `product`. Keeping `out_type` by value with
`out_type(std::move(out_type))` and reading `*this->out_type` in `product(...)`
avoids a copy for rvalue callers.
##########
cpp/src/arrow/engine/substrait/relation_internal.cc:
##########
@@ -332,7 +332,7 @@ Result<compute::Aggregate> ParseAggregateMeasure(
}
ARROW_ENGINE_EXPORT Result<DeclarationInfo> MakeAggregateDeclaration(
- acero::Declaration input_decl, std::shared_ptr<Schema> aggregate_schema,
+ acero::Declaration input_decl, const std::shared_ptr<Schema>&
aggregate_schema,
Review Comment:
🤖 -> `MakeAggregateDeclaration` stores `aggregate_schema` in the returned
`DeclarationInfo`, and `options.cc` already passes
`std::move(aggregate_schema)` here. Keeping it by value (in both `.h` and
`.cc`) and moving it into `DeclarationInfo` avoids a copy for rvalue callers
and leaves the `ARROW_ENGINE_EXPORT` signature unchanged.
--
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]