-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Eliminate unnecessary refcount traffic from shared_ptr parameters passed by value that don't need to be
#51270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -274,7 +274,7 @@ struct GatedNode : public ExecNode, public TracedNode { | |
| } | ||
|
|
||
| GatedNode(ExecPlan* plan, std::vector<ExecNode*> inputs, | ||
| std::shared_ptr<Schema> output_schema, const GatedNodeOptions& options) | ||
| const std::shared_ptr<Schema>& output_schema, const GatedNodeOptions& options) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong too: the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks again. For reading convenience here's the whole function as it is today: GatedNode(ExecPlan* plan, std::vector<ExecNode*> inputs,
std::shared_ptr<Schema> output_schema, const GatedNodeOptions& options)
: ExecNode(plan, inputs, {"input"}, output_schema),
TracedNode(this),
gate_(options.gate) {}First, I think we agree there's a performance bug? We agree this function should be changed and that there is a needless copy, right? This is a good thing! Alternative 1 (this PR): The PR's proposed change to pass
Alternative 2 (add
Isn't this PR's suggestion worth considering, to change a copy to nothing at all and with arguably simpler code? Again, sorry if I'm missing something! (In particular, I have no idea whether these signatures I'm proposing to change might be exported/API functions, e.g., for use in cross-language APIs, that must be pass by value and can't tolerate pass by Thank you for your feedback. |
||
| : ExecNode(plan, inputs, {"input"}, output_schema), | ||
| TracedNode(this), | ||
| gate_(options.gate) {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,7 +135,7 @@ constexpr int64_t kReadRowsBatch = 1000; | |
| class OrcStripeReader : public RecordBatchReader { | ||
| public: | ||
| OrcStripeReader(std::unique_ptr<liborc::RowReader> row_reader, | ||
| std::shared_ptr<Schema> schema, int64_t batch_size, MemoryPool* pool) | ||
| const std::shared_ptr<Schema>& schema, int64_t batch_size, MemoryPool* pool) | ||
| : row_reader_(std::move(row_reader)), | ||
| schema_(schema), | ||
|
Comment on lines
+138
to
140
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: should move the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would repeat the same considerations as in my reply about |
||
| pool_(pool), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right.
MakeIteratorFromReadershould instead take its argument by value instead of const-ref.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitrou, thanks again.
Can you help me to understand this feedback please...
I'm not sure how
MakeIteratorFromReaderis related. That's outside the lambda whose parameter is being changed here?The lambda only dereferences
batch. Doesn't currently takingbatchby value add a (needless?) inc/dec on the refcount? Isn't changing it to pass byconst&a strict improvement?Again, my apologies if I'm missing something here or asking a silly question! I don't know this code base well and I appreciate your feedback.