[webkit-changes] [WebKit/WebKit] fe0d0e: [JSC] Make C++ -> JS calls faster

Yusuke Suzuki noreply at github.com
Sun Feb 26 14:36:04 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: fe0d0e1818d0267e38495a3935584229e1625525
      https://github.com/WebKit/WebKit/commit/fe0d0e1818d0267e38495a3935584229e1625525
  Author: Yusuke Suzuki <ysuzuki at apple.com>
  Date:   2023-02-26 (Sun, 26 Feb 2023)

  Changed paths:
    A JSTests/microbenchmarks/cpp-to-js-call.js
    M Source/JavaScriptCore/CMakeLists.txt
    M Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
    M Source/JavaScriptCore/debugger/Debugger.cpp
    M Source/JavaScriptCore/dfg/DFGOperations.cpp
    M Source/JavaScriptCore/interpreter/CallFrame.cpp
    M Source/JavaScriptCore/interpreter/Interpreter.cpp
    M Source/JavaScriptCore/runtime/ExceptionScope.h
    M Source/JavaScriptCore/runtime/StringPrototype.cpp
    M Source/JavaScriptCore/runtime/VM.cpp
    M Source/JavaScriptCore/runtime/VM.h
    M Source/JavaScriptCore/runtime/VMEntryScope.cpp
    M Source/JavaScriptCore/runtime/VMEntryScope.h
    A Source/JavaScriptCore/runtime/VMEntryScopeInlines.h
    M Source/JavaScriptCore/runtime/VMTraps.cpp
    M Source/JavaScriptCore/tools/JSDollarVM.cpp
    M Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
    M Source/WebCore/bindings/js/JSErrorHandler.cpp
    M Source/WebCore/bindings/js/JSEventListener.cpp

  Log Message:
  -----------
  [JSC] Make C++ -> JS calls faster
https://bugs.webkit.org/show_bug.cgi?id=252961
rdar://105943509

Reviewed by Mark Lam.

1. VMEntryScope's fast path should be inlined. Do it to make it work when it is used outside of JSC framework (WebCore etc.).
2. Move VMEntryScope's didPopListener to VM so that it makes VMEntryScope's destructor super simple (purge Vector destructor code bloat).
3. Remove isCollectorBusyOnCurrentThread check. It is extremely costly for this function (5% is attributed to this!). It is too costly
   for runtime check. And we instead have ASSERT already, which should catch an issue from fuzzers (And so far, we are not seeing this).
4. RETURN_IF_EXCEPTION inside DeferTraps always get the slow path function call! We call `vm.traps().needHandling(VMTraps::AllEvents)` manually
   to avoid this.

This patch makes C++ -> JS calls 8% faster.

                               ToT                     Patched

    cpp-to-js-call       85.4401+-0.4316     ^     78.9938+-0.3521        ^ definitely 1.0816x faster

* JSTests/microbenchmarks/cpp-to-js-call.js: Added.
(test):
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/debugger/Debugger.cpp:
* Source/JavaScriptCore/dfg/DFGOperations.cpp:
* Source/JavaScriptCore/interpreter/CallFrame.cpp:
* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::Interpreter::executeProgram):
(JSC::Interpreter::executeCallImpl):
(JSC::Interpreter::executeConstruct):
(JSC::Interpreter::prepareForRepeatCall):
(JSC::Interpreter::executeEval):
(JSC::Interpreter::executeModuleProgram):
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
* Source/JavaScriptCore/runtime/VM.cpp:
(JSC::VM::whenIdle):
* Source/JavaScriptCore/runtime/VM.h:
(JSC::VM::invokeDidPopListeners):
* Source/JavaScriptCore/runtime/VMEntryScope.cpp:
(JSC::VMEntryScope::setUpSlow):
(JSC::VMEntryScope::tearDownSlow):
(JSC::VMEntryScope::VMEntryScope): Deleted.
(JSC::VMEntryScope::addDidPopListener): Deleted.
(JSC::VMEntryScope::~VMEntryScope): Deleted.
* Source/JavaScriptCore/runtime/VMEntryScope.h:
* Source/JavaScriptCore/runtime/VMEntryScopeInlines.h: Copied from Source/JavaScriptCore/runtime/VMEntryScope.h.
(JSC::VMEntryScope::VMEntryScope):
(JSC::VMEntryScope::~VMEntryScope):
* Source/JavaScriptCore/runtime/VMTraps.cpp:
* Source/JavaScriptCore/tools/JSDollarVM.cpp:
* Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:
* Source/WebCore/bindings/js/JSErrorHandler.cpp:
* Source/WebCore/bindings/js/JSEventListener.cpp:

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




More information about the webkit-changes mailing list