Closed Bug 1845668 Opened 10 months ago Closed 9 months ago

Directly use TaskController to trigger the equivalent of OffThreadCompilationCompleteRunnable

Categories

(Core :: DOM: Core & HTML, task, P3)

task

Tracking

()

RESOLVED FIXED
119 Branch
Tracking Status
firefox119 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(2 files)

Bug 1845638 is going to change the off-thread compilation/decode to directly use TaskController task.

mozilla::dom::OffThreadCompilationCompleteRunnable is currently using Runnable and nsIEventTarget::Dispatch to enqueue the task, but it eventually enqueues a RunnableTask to TaskContoller, going through many hoops [1].

Given the depending task (compilation/decoding) is going to use Task, it's better just directly using Task also for OffThreadCompilationCompleteRunnable-equivalent, and use the TaskController's dependency management.

[1]
https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/dom/script/ScriptLoader.cpp#1686-1687,1696

void ScriptLoader::OffThreadCompilationCompleteCallback(
    JS::OffThreadToken* aToken, void* aCallbackData) {
...
  OffThreadCompilationCompleteRunnable::Dispatch(aRunnable.forget());

https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/dom/script/ScriptLoader.cpp#1502,1506

static void Dispatch(
...
  eventTarget->Dispatch(self.forget());

https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/xpcom/threads/nsThread.cpp#686,692

nsThread::Dispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags) {
...
  return mEventTarget->Dispatch(std::move(aEvent), aFlags);

https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/xpcom/threads/ThreadEventTarget.cpp#66,92

ThreadEventTarget::Dispatch(already_AddRefed<nsIRunnable> aEvent,
...
  if (!mSink->PutEvent(event.take(), EventQueuePriority::Normal)) {

https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/xpcom/threads/ThreadEventQueue.cpp#28,30

bool PutEvent(already_AddRefed<nsIRunnable>&& aEvent,
...
  return mOwner->PutEventInternal(std::move(aEvent), aPriority, this);

https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/xpcom/threads/ThreadEventQueue.cpp#76,131

bool ThreadEventQueue::PutEventInternal(already_AddRefed<nsIRunnable>&& aEvent,
...
      mBaseQueue->PutEvent(event.take(), aPriority, lock);

https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/xpcom/threads/EventQueue.cpp#19,42,55-56

void EventQueueInternal<ItemsPerPage>::PutEvent(
...
  if (mForwardToTC) {
...
    tc->DispatchRunnable(event.forget(), static_cast<uint32_t>(aPriority),
                         manager);

https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/xpcom/threads/TaskController.cpp#591,594-595,598

void TaskController::DispatchRunnable(already_AddRefed<nsIRunnable>&& aRunnable,
...
  RefPtr<RunnableTask> task = new RunnableTask(std::move(aRunnable), aPriority,
                                               Task::Kind::MainThreadOnly);
...
  TaskController::Get()->AddTask(task.forget());
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/dce19aa8ece9
Part 1: Rewrite OffThreadCompilationCompleteRunnable based on Task. r=smaug
https://hg.mozilla.org/integration/autoland/rev/0b374bcf3727
Part 2: Move OffThreadCompilationCompleteTask::Run into class definition. r=smaug
Status: ASSIGNED → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → 119 Branch
Regressions: 1851578
Regressions: 1853752
No longer regressions: 1853752
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: