Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9d9aae7cdf45509e1db82e3ae563cbd650508fee
      
https://github.com/WebKit/WebKit/commit/9d9aae7cdf45509e1db82e3ae563cbd650508fee
  Author: Yusuke Suzuki <[email protected]>
  Date:   2026-02-20 (Fri, 20 Feb 2026)

  Changed paths:
    M Source/JavaScriptCore/CMakeLists.txt
    M Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
    M Source/JavaScriptCore/Sources.txt
    M Source/JavaScriptCore/heap/Heap.cpp
    M Source/JavaScriptCore/heap/Heap.h
    M Source/JavaScriptCore/runtime/JSGlobalObject.cpp
    M Source/JavaScriptCore/runtime/JSGlobalObject.h
    A Source/JavaScriptCore/runtime/JSMicrotaskDispatcher.cpp
    A Source/JavaScriptCore/runtime/JSMicrotaskDispatcher.h
    M Source/JavaScriptCore/runtime/JSType.cpp
    M Source/JavaScriptCore/runtime/JSType.h
    M Source/JavaScriptCore/runtime/Microtask.h
    M Source/JavaScriptCore/runtime/MicrotaskQueue.cpp
    M Source/JavaScriptCore/runtime/MicrotaskQueue.h
    M Source/JavaScriptCore/runtime/MicrotaskQueueInlines.h
    M Source/JavaScriptCore/runtime/VM.cpp
    M Source/JavaScriptCore/runtime/VM.h
    M Source/WebCore/bindings/js/JSDOMWindowBase.cpp
    M Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp
    M Source/WebCore/bindings/js/ScriptController.cpp
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/dom/EventLoop.cpp
    M Source/WebCore/dom/EventLoop.h
    M Source/WebCore/dom/Microtasks.cpp
    M Source/WebCore/dom/Microtasks.h
    M Source/WebCore/dom/ScriptExecutionContext.cpp
    M Source/WebCore/dom/ScriptExecutionContext.h
    M Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp
    M Source/WebCore/workers/WorkerOrWorkletGlobalScope.h
    M Source/WebCore/workers/WorkerOrWorkletScriptController.cpp

  Log Message:
  -----------
  MicrotaskDispatcher should be JSCell
https://bugs.webkit.org/show_bug.cgi?id=308264
rdar://170765991

Reviewed by Yijia Huang.

Under incredible amount of QueuedTasks, even ref / deref is costly. And
accessing EventLoopTaskGroup's WeakPtr (and involving indirections) is
also costly too.

1. We introduce JSMicrotaskDispatcher JSCell. And use it in QueuedTask
   instead of Ref<MicrotaskDispatcher>. This removes ref / deref since
   it is no GC managed. MicrotaskQueue visits them correctly (along with
   the other JSValues as well).
2. JSMicrotaskDispatcher has inlined fields for the current associated
   dispatcher's state (runnability). And EventLoopTaskGroup will update
   this proactively instead of pulling information from them. This is
   much more efficient: we peek this information for each microtask, but
   EventLoopTaskGroup does not update this state so frequently.
3. Since EventLoop is associated with ScriptExecutionContext, and it is
   tied to JSGlobalObject, we now store runnability information to
   JSGlobalObject, and store JSGlobalObject to dispatcher field for
   common cases. Thus we can unify JSMicrotaskDispatcher and
   JSGlobalObject field in QueuedTask, which shrinks sizeof(QueuedTask).
   This is critical for performance. Note that this patch is 100% aware
   that EventLoopTaskGroup v.s. JSGlobalObject is N:1 relationship. We
   store this runnability information of the *default*
   EventLoopTaskGroup for the JSGlobalObject.
4. We make sure that QueuedTask is now trivially destrucible because we
   no longer have Ref<>. Also we ensure that this is now POD and can be
   initialized with memset, and even copied with memcpy etc.
5. Also move JSGlobalObject::m_debugger field to the first fields to
   make it hit in the cache. m_debugger is frequently accessed to ensure
   m_debugger is *not* instantiated.

* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/heap/Heap.cpp:
* Source/JavaScriptCore/heap/Heap.h:
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::queueMicrotaskToEventLoop):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::microtaskRunnability const):
(JSC::JSGlobalObject::setMicrotaskRunnability):
* Source/JavaScriptCore/runtime/JSMicrotaskDispatcher.cpp: Added.
(JSC::JSMicrotaskDispatcher::createStructure):
(JSC::JSMicrotaskDispatcher::create):
(JSC::JSMicrotaskDispatcher::JSMicrotaskDispatcher):
(JSC::JSMicrotaskDispatcher::visitChildrenImpl):
(JSC::JSMicrotaskDispatcher::destroy):
* Source/JavaScriptCore/runtime/JSMicrotaskDispatcher.h: Added.
* Source/JavaScriptCore/runtime/JSType.cpp:
(WTF::printInternal):
* Source/JavaScriptCore/runtime/JSType.h:
* Source/JavaScriptCore/runtime/Microtask.h:
* Source/JavaScriptCore/runtime/MicrotaskQueue.cpp:
(JSC::QueuedTask::isRunnable const):
(JSC::MarkedMicrotaskDeque::visitAggregateImpl):
* Source/JavaScriptCore/runtime/MicrotaskQueue.h:
(JSC::QueuedTask::QueuedTask):
(JSC::QueuedTask::setDispatcher):
(JSC::QueuedTask::dispatcher const): Deleted.
(JSC::QueuedTask::identifier const):
(JSC::QueuedTask::globalObject const): Deleted.
* Source/JavaScriptCore/runtime/MicrotaskQueueInlines.h:
(JSC::QueuedTask::dispatcher const):
(JSC::QueuedTask::globalObject const):
(JSC::QueuedTask::jsMicrotaskDispatcher const):
(JSC::QueuedTask::identifier const):
* Source/JavaScriptCore/runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::drainMicrotasks):
(JSC::VM::visitAggregateImpl):
* Source/JavaScriptCore/runtime/VM.h:
* Source/WebCore/bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::queueMicrotaskToEventLoop):
* Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp:
(WebCore::JSWorkerGlobalScopeBase::queueMicrotaskToEventLoop):
* Source/WebCore/bindings/js/ScriptController.cpp:
(WebCore::ScriptController::initScriptForWindowProxy):
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::commonTeardown):
(WebCore::Document::isEventLoopGroupStoppedPermanently const):
(WebCore::Document::eventLoop):
* Source/WebCore/dom/Document.h:
* Source/WebCore/dom/EventLoop.cpp:
(WebCore::EventLoopTaskGroup::EventLoopTaskGroup):
(WebCore::EventLoopTaskGroup::jsMicrotaskDispatcherForDebugger):
(WebCore::EventLoopTaskGroup::setScriptExecutionContext):
(WebCore::EventLoopTaskGroup::stopAndDiscardAllTasks):
(WebCore::EventLoopTaskGroup::queueMicrotask):
(WebCore::EventLoopTaskGroup::jsMicrotaskDispatcher):
* Source/WebCore/dom/EventLoop.h:
* Source/WebCore/dom/Microtasks.cpp:
(WebCore::MicrotaskQueue::performMicrotaskCheckpoint):
* Source/WebCore/dom/Microtasks.h:
* Source/WebCore/dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::setMicrotaskGlobalObject):
(WebCore::ScriptExecutionContext::microtaskGlobalObject const):
(WebCore::ScriptExecutionContext::clearMicrotaskGlobalObject):
(WebCore::ScriptExecutionContext::suspendActiveDOMObjects):
(WebCore::ScriptExecutionContext::resumeActiveDOMObjects):
* Source/WebCore/dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::isEventLoopGroupStoppedPermanently const):
* Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp:
(WebCore::WorkerOrWorkletGlobalScope::prepareForDestruction):
(WebCore::WorkerOrWorkletGlobalScope::eventLoop):
(WebCore::WorkerOrWorkletGlobalScope::isEventLoopGroupStoppedPermanently const):
* Source/WebCore/workers/WorkerOrWorkletGlobalScope.h:
* Source/WebCore/workers/WorkerOrWorkletScriptController.cpp:
(WebCore::WorkerOrWorkletScriptController::initScriptWithSubclass):

Canonical link: https://commits.webkit.org/307966@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to