yuxihu commented on a change in pull request #14665: [performance] Avoid 
uneccesary vector copies in imperative_utils.cc
URL: https://github.com/apache/incubator-mxnet/pull/14665#discussion_r274159399
 
 

 ##########
 File path: src/imperative/imperative_utils.cc
 ##########
 @@ -20,62 +20,61 @@
 #include "./imperative_utils.h"
 #include "./cached_op.h"
 
-namespace mxnet {
-namespace imperative {
+namespace {
 
-inline std::vector<NDArray*> NodeInputs(const nnvm::IndexedGraph& idx,
-                                        const int node_idx,
-                                        const std::vector<NDArray*> arrays) {
+std::vector<NDArray*> NodeInputs(const nnvm::IndexedGraph& idx,
+                                 const int node_idx,
+                                 const std::vector<NDArray*>& arrays) {
   const nnvm::IndexedGraph::Node& node = idx[node_idx];
   const size_t num_inputs = node.inputs.size();
   std::vector<NDArray*> ndinputs;
   ndinputs.reserve(num_inputs);
   for (const auto& j : node.inputs) {
-    size_t eid = idx.entry_id(j);
+    const size_t eid = idx.entry_id(j);
     ndinputs.emplace_back(arrays[eid]);
   }
   return ndinputs;
 }
 
-inline std::vector<NDArray*> NodeOutputs(const nnvm::IndexedGraph& idx,
-                                         const int node_idx,
-                                         const std::vector<NDArray*> arrays) {
+std::vector<NDArray*> NodeOutputs(const nnvm::IndexedGraph& idx,
+                                  const int node_idx,
+                                  const std::vector<NDArray*>& arrays) {
   const nnvm::IndexedGraph::Node& node = idx[node_idx];
   const size_t num_outputs = node.source->num_outputs();
   std::vector<NDArray*> ndoutputs;
   ndoutputs.reserve(num_outputs);
   for (size_t j = 0; j < num_outputs; ++j) {
-    size_t eid = idx.entry_id(node_idx, j);
+    const size_t eid = idx.entry_id(node_idx, j);
     ndoutputs.emplace_back(arrays[eid]);
   }
   return ndoutputs;
 }
 
-inline std::vector<OpReqType> NodeReq(const nnvm::IndexedGraph& idx,
-                                      const int node_idx,
-                                      const std::vector<OpReqType> array_reqs) 
{
+std::vector<OpReqType> NodeReq(const nnvm::IndexedGraph& idx,
 
 Review comment:
   Can we pass in the returned vector `std::vector<OpReqType>` so we can save 
another copy?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to