westonpace commented on a change in pull request #9644: URL: https://github.com/apache/arrow/pull/9644#discussion_r598045583
########## File path: cpp/src/arrow/util/thread_pool.h ########## @@ -102,16 +102,34 @@ class ARROW_EXPORT Executor { // CPU heavy work off the I/O thread pool. So the I/O task should transfer // the future to the CPU executor before returning. template <typename T> - Future<T> Transfer(Future<T> future) { + Future<T> Transfer(Future<T> future, bool force_spawn = false) { auto transferred = Future<T>::Make(); - future.AddCallback([this, transferred](const Result<T>& result) mutable { + auto callback = [this, transferred](const Result<T>& result) mutable { auto spawn_status = Spawn([transferred, result]() mutable { transferred.MarkFinished(std::move(result)); }); if (!spawn_status.ok()) { transferred.MarkFinished(spawn_status); } - }); + }; + auto callback_factory = [&callback]() { return callback; }; + auto callback_added = future.TryAddCallback(callback_factory); + if (!callback_added) { + if (force_spawn) { + auto spawn_status = Spawn([future, transferred]() mutable { + transferred.MarkFinished(future.result()); + }); + if (!spawn_status.ok()) { + transferred.MarkFinished(spawn_status); + } + return transferred; Review comment: Ok. The "force_spawn" has been removed. Using the instrumentation I worked on yesterday I tracked the issue down to a few other spots that didn't really have anything to do with needing to transfer. On the bright side, this actually eliminated the 2-5% slowdown I was seeing so the performance now matches the synchronous version. -- 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