gemini-code-assist[bot] commented on code in PR #19767:
URL: https://github.com/apache/tvm/pull/19767#discussion_r3409927575


##########
src/s_tir/meta_schedule/task_scheduler/task_scheduler.cc:
##########
@@ -205,7 +205,18 @@ void TaskSchedulerNode::Tune(ffi::Array<TuneContext> ctxs, 
ffi::Array<FloatImm>
       num_trials_already += num_candidates;
       TVM_PY_LOG(INFO, this->logger) << "Sending " << num_candidates << " 
sample(s) to builder";
       SendToBuilder(task, builder);
-      TVM_PY_LOG(INFO, this->logger) << "Sending " << num_candidates << " 
sample(s) to runner";
+      int n_build_errs = 0;
+      const int n_build_size = task->builder_results.value().size();
+      for (int i = 0; i < n_build_size; i++) {
+        if (task->builder_results.value()[i]->error_msg.has_value())
+          ++n_build_errs;
+      }

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Calling `task->builder_results.value()` inside the loop is inefficient 
because it repeatedly unwraps the `Optional` and potentially copies or 
increments/decrements the reference count of the `ffi::Array` on every 
iteration. It is much more efficient to retrieve the array once before the loop.
   
   ```c
         int n_build_errs = 0;
         const ffi::Array<BuilderResult>& builder_results = 
task->builder_results.value();
         const int n_build_size = builder_results.size();
         for (int i = 0; i < n_build_size; i++) {
           if (builder_results[i]->error_msg.has_value())
             ++n_build_errs;
         }
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to