Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: f70f597b849ebd6561da99753d8e81d7586650d3
      
https://github.com/WebKit/WebKit/commit/f70f597b849ebd6561da99753d8e81d7586650d3
  Author: Yusuke Suzuki <[email protected]>
  Date:   2025-11-18 (Tue, 18 Nov 2025)

  Changed paths:
    M Source/JavaScriptCore/CMakeLists.txt
    M Source/JavaScriptCore/DerivedSources-input.xcfilelist
    M Source/JavaScriptCore/DerivedSources.make
    M Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
    R Source/JavaScriptCore/builtins/AsyncFunctionPrototype.js
    M Source/JavaScriptCore/builtins/BuiltinNames.h
    M Source/JavaScriptCore/bytecode/LinkTimeConstant.h
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
    M Source/JavaScriptCore/interpreter/Interpreter.cpp
    M Source/JavaScriptCore/runtime/JSAsyncGenerator.h
    M Source/JavaScriptCore/runtime/JSGenerator.h
    M Source/JavaScriptCore/runtime/JSGlobalObject.cpp
    M Source/JavaScriptCore/runtime/JSMicrotask.cpp
    M Source/JavaScriptCore/runtime/JSPromise.cpp
    M Source/JavaScriptCore/runtime/JSPromise.h
    M Source/JavaScriptCore/runtime/Microtask.h

  Log Message:
  -----------
  [JSC] Async Function should be driven directly via MicrotaskQueue
https://bugs.webkit.org/show_bug.cgi?id=302677
rdar://164925036

Reviewed by Yijia Huang.

We were scheduling next invocation of async function via
@resolveWithoutPromiseForAsyncAwait and passing
@asyncFunctionResumeOnFulfilled and @asyncFunctionResumeOnRejected
functions. And @asyncFunctionResume is invoked from them. But this is
inefficient in two ways.

1. These functions are completely builtin. We do not need to have them
   in JS.
2. MicrotaskQueue invokes these functions from C++ world, and then
   @asyncFunctionResume invokes actual async function in the one place.
   This is double-dispatch and we do not need to pay this cost. It
   should be only one dynamic dispatch.

This patch implements these builtin JS logic in MicrotaskQueue itself.
And now MicrotaskQueue directly dispatches user-defined async functions.
JSPromise / MicrotaskQueue extend WithInternalMicrotask variants and
start using it for these async function driving. In the future, we would
like to completely replace WithoutPromise variants with this 
WithInternalMicrotask
variants.

We also inline asyncFunctionResume completely to the async wrapper
function itself. This function is doing double-dispatch unnecessary and
we should have unique call site into the user-provided function not to
cause megamorphic calls.

We also shrink the size of JSGenerator and JSAsyncGenerator as we are
not using these PolyProto field so far.

* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/DerivedSources-input.xcfilelist:
* Source/JavaScriptCore/DerivedSources.make:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/builtins/AsyncFunctionPrototype.js:
* Source/JavaScriptCore/builtins/BuiltinNames.h:
* Source/JavaScriptCore/bytecode/LinkTimeConstant.h:
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::FunctionNode::emitBytecode):
* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::Interpreter::getStackTrace):
* Source/JavaScriptCore/runtime/JSAsyncGenerator.h:
* Source/JavaScriptCore/runtime/JSGenerator.h:
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
(JSC::JSGlobalObject::init):
* Source/JavaScriptCore/runtime/JSMicrotask.cpp:
(JSC::promiseResolveThenableJobWithInternalMicrotaskFastSlow):
(JSC::runInternalMicrotask):
* Source/JavaScriptCore/runtime/JSPromise.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
(JSC::JSPromise::triggerPromiseReactions):
(JSC::JSPromise::resolveWithInternalMicrotaskForAsyncAwait):
(JSC::JSPromise::resolveWithInternalMicrotask):
(JSC::JSPromise::rejectWithInternalMicrotask):
(JSC::JSPromise::fulfillWithInternalMicrotask):
* Source/JavaScriptCore/runtime/JSPromise.h:
* Source/JavaScriptCore/runtime/Microtask.h:

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



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

Reply via email to