From f10a598e34da5ea4060ccfb8a027dd5c37c108c0 Mon Sep 17 00:00:00 2001 From: Derek Murray Date: Fri, 22 Dec 2017 15:39:18 -0800 Subject: [PATCH] Avoid unnecessary copying and allocation in `ExecutorBarrier::WhenDone()`. Previously the code would make a copy of the `done_cb_` and update the status on a successful completion, neither of which is necessary, and both of which showed up in trace amounts in profiling. PiperOrigin-RevId: 179970701 --- tensorflow/core/common_runtime/executor.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tensorflow/core/common_runtime/executor.h b/tensorflow/core/common_runtime/executor.h index b5f4ebb0053..3fd932da5b6 100644 --- a/tensorflow/core/common_runtime/executor.h +++ b/tensorflow/core/common_runtime/executor.h @@ -202,11 +202,12 @@ class ExecutorBarrier { // below. if (--pending_ == 0) { CHECK(done_cb_ != nullptr); - done = done_cb_; - done_cb_ = nullptr; + std::swap(done, done_cb_); } - status = status_; + if (!status_.ok()) { + status = status_; + } } if (error) {