[Webkit-unassigned] [Bug 203463] New: JSC C API unusably slow because of JSLock / Provide explicit locking API

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Oct 26 14:01:56 PDT 2019


https://bugs.webkit.org/show_bug.cgi?id=203463

            Bug ID: 203463
           Summary: JSC C API unusably slow because of JSLock / Provide
                    explicit locking API
           Product: WebKit
           Version: Other
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: radexpl at gmail.com

All JSC C API calls create a JSLockHolder object, which… I assume has something to do with thread safety, but I'm not sure if it's just meant to prevent concurrent JSC API calls, or if it's used internally in JSI as well.

Either way, using JSC C API on a large structure (say, calling a native function from JS, passing an array with 30000 elements, and then iterating it in native code to construct platform-specific objects) is very, very slow because of this locking behavior. The locks get set up and torn down something like a hundred thousand times in my example.

This is a real bottleneck when JSC is used extensively, e.g. for react-native's jsi (see https://github.com/facebook/react-native/pull/27016 as an example of this) — the vast majority of the time doing such a conversion (hundreds of ms in my 30K array example) is spent on locks.

My understanding is that this problem would disappear completely if a single JSLockHandler was set up before a large operation involving using JSC, and torn down afterwards, since actual locking is skipped if there's already a lock for the current thread (https://github.com/WebKit/webkit/blob/master/Source/JavaScriptCore/runtime/JSLock.cpp#L114-L115).

This seems to happen in the ObjC JSC API: https://github.com/WebKit/webkit/blob/3816a3012159e90c1b54d06d80fc4c7e6fc375df/Source/JavaScriptCore/API/JSValue.mm#L728 -- but if you want to do JS-native structure conversion not to ObjC but in C land or for C++ for very high performance on Apple platforms, no luck.

But JSLockHandler API is not exposed in public Apple APIs, or any alternative (like a theoretical JSLock(ctx) JSUnlock(ctx) api).

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20191026/66de5121/attachment-0001.htm>


More information about the webkit-unassigned mailing list