Commit d88568eb authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[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/+/2414028Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69976}
parent baad3460
......@@ -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(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment