Skip to content

Commit

Permalink
Do not create unnecessary strings for each posted task
Browse files Browse the repository at this point in the history
Reduces one of the hot spots in early startup.

Change-Id: I0fbf412a14cf1e31bbfe601d523fb8169fb73a99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523241
Commit-Queue: ssid <ssid@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825055}
  • Loading branch information
ssiddhartha authored and Commit Bot committed Nov 6, 2020
1 parent 8b5342b commit e1f712f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 13 additions & 0 deletions base/critical_closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>

#include "base/callback.h"
#include "base/location.h"
#include "base/strings/string_piece.h"
#include "build/build_config.h"

Expand Down Expand Up @@ -66,13 +67,25 @@ inline OnceClosure MakeCriticalClosure(StringPiece task_name,
&internal::CriticalClosure::Run,
Owned(new internal::CriticalClosure(task_name, std::move(closure))));
}

inline OnceClosure MakeCriticalClosure(const Location& posted_from,
OnceClosure closure) {
return MakeCriticalClosure(posted_from.ToString(), std::move(closure));
}

#else // defined(OS_IOS)
inline OnceClosure MakeCriticalClosure(StringPiece task_name,
OnceClosure closure) {
// No-op for platforms where the application does not need to acquire
// background time for closures to finish when it goes into the background.
return closure;
}

inline OnceClosure MakeCriticalClosure(const Location& posted_from,
OnceClosure closure) {
return closure;
}

#endif // defined(OS_IOS)

} // namespace base
Expand Down
3 changes: 1 addition & 2 deletions base/task/thread_pool/sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void Sequence::Transaction::PushTask(Task task) {

task.task = sequence()->traits_.shutdown_behavior() ==
TaskShutdownBehavior::BLOCK_SHUTDOWN
? MakeCriticalClosure(task.posted_from.ToString(),
std::move(task.task))
? MakeCriticalClosure(task.posted_from, std::move(task.task))
: std::move(task.task);

if (sequence()->queue_.empty())
Expand Down

0 comments on commit e1f712f

Please sign in to comment.