[wasm] Speed up waiting for events

In many cases, the event we are waiting for already happened. In that
case, entering the {ExecuteCompilationUnits} function creates
significant overhead.

This CL fixes this by just checking whether the event we are waiting for
already happened, and returning early in that case. This should restore
the original performance before https://crrev.com/c/2351671.

R=thibaudm@chromium.org

Bug: v8:10922
Change-Id: I5229808162a3b348bbbb067bd10065894c8a655c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2414028
Reviewed-by: Thibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69976}
This commit is contained in:
Clemens Backes 2020-09-16 12:40:31 +02:00 committed by Commit Bot
parent baad346049
commit d88568eb3e

View File

@ -3268,13 +3268,16 @@ void CompilationStateImpl::SetError() {
void CompilationStateImpl::WaitForCompilationEvent(
CompilationEvent expect_event) {
auto compilation_event_semaphore = std::make_shared<base::Semaphore>(0);
AddCallback(
[compilation_event_semaphore, expect_event](CompilationEvent event) {
if (event == expect_event ||
event == CompilationEvent::kFailedCompilation) {
compilation_event_semaphore->Signal();
}
});
base::EnumSet<CompilationEvent> events{expect_event,
CompilationEvent::kFailedCompilation};
{
base::MutexGuard callbacks_guard(&callbacks_mutex_);
if (finished_events_.contains_any(events)) return;
callbacks_.emplace_back(
[compilation_event_semaphore, events](CompilationEvent event) {
if (events.contains(event)) compilation_event_semaphore->Signal();
});
}
constexpr JobDelegate* kNoDelegate = nullptr;
ExecuteCompilationUnits(background_compile_token_, async_counters_.get(),