Commit a2993308 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by V8 LUCI CQ

[gc] Use CreateJob().Join() in v8 gc to avoid extra context switches

CreateJob() doesn't schedule anything until Join() or Notify*() is called. CreateJob().Join() will thus schedule the right number of
workers for the job right away (taking into account the main thread
contributes), whereas PostJob().Join() schedules 1 worker that won't
be necessary once doing Join() and the main thread kicks in.
This has the effect of reducing 1 unnecessary context switch each time
the jobs are schedule.

Bug: chromium:1287665
Change-Id: Ie262f8904cc8ac78d9e5cbd23ef28dc5b013a625
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3746080Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82047}
parent 0d0e73e6
......@@ -4207,7 +4207,7 @@ size_t CreateAndExecuteEvacuationTasks(
evacuators.push_back(std::move(evacuator));
}
V8::GetCurrentPlatform()
->PostJob(
->CreateJob(
v8::TaskPriority::kUserBlocking,
std::make_unique<PageEvacuationJob>(collector->isolate(), &evacuators,
std::move(evacuation_items)))
......@@ -4965,11 +4965,12 @@ void MarkCompactCollector::UpdatePointersAfterEvacuation() {
std::make_unique<EphemeronTableUpdatingItem>(heap()));
V8::GetCurrentPlatform()
->PostJob(v8::TaskPriority::kUserBlocking,
std::make_unique<PointersUpdatingJob>(
isolate(), std::move(updating_items),
GCTracer::Scope::MC_EVACUATE_UPDATE_POINTERS_PARALLEL,
GCTracer::Scope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS))
->CreateJob(
v8::TaskPriority::kUserBlocking,
std::make_unique<PointersUpdatingJob>(
isolate(), std::move(updating_items),
GCTracer::Scope::MC_EVACUATE_UPDATE_POINTERS_PARALLEL,
GCTracer::Scope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS))
->Join();
}
......@@ -5555,7 +5556,7 @@ void MinorMarkCompactCollector::UpdatePointersAfterEvacuation() {
TRACE_GC(heap()->tracer(),
GCTracer::Scope::MINOR_MC_EVACUATE_UPDATE_POINTERS_SLOTS);
V8::GetCurrentPlatform()
->PostJob(
->CreateJob(
v8::TaskPriority::kUserBlocking,
std::make_unique<PointersUpdatingJob>(
isolate(), std::move(updating_items),
......@@ -6054,10 +6055,10 @@ void MinorMarkCompactCollector::MarkRootSetInParallel(
local_marking_worklists_->Publish();
TRACE_GC(heap()->tracer(), GCTracer::Scope::MINOR_MC_MARK_ROOTS);
V8::GetCurrentPlatform()
->PostJob(v8::TaskPriority::kUserBlocking,
std::make_unique<YoungGenerationMarkingJob>(
isolate(), this, marking_worklists(),
std::move(marking_items)))
->CreateJob(v8::TaskPriority::kUserBlocking,
std::make_unique<YoungGenerationMarkingJob>(
isolate(), this, marking_worklists(),
std::move(marking_items)))
->Join();
DCHECK(local_marking_worklists_->IsEmpty());
......
......@@ -373,10 +373,10 @@ void ScavengerCollector::CollectGarbage() {
// Parallel phase scavenging all copied and promoted objects.
TRACE_GC(heap_->tracer(), GCTracer::Scope::SCAVENGER_SCAVENGE_PARALLEL);
V8::GetCurrentPlatform()
->PostJob(v8::TaskPriority::kUserBlocking,
std::make_unique<JobTask>(this, &scavengers,
std::move(memory_chunks),
&copied_list, &promotion_list))
->CreateJob(v8::TaskPriority::kUserBlocking,
std::make_unique<JobTask>(this, &scavengers,
std::move(memory_chunks),
&copied_list, &promotion_list))
->Join();
DCHECK(copied_list.IsEmpty());
DCHECK(promotion_list.IsEmpty());
......
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