<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>203463</bug_id>
          
          <creation_ts>2019-10-26 14:01:56 -0700</creation_ts>
          <short_desc>JSC C API unusably slow because of JSLock / Provide explicit locking API</short_desc>
          <delta_ts>2022-06-24 17:10:01 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Radek Pietruszewski">radexpl</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>mark.lam</cc>
    
    <cc>saam</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1584271</commentid>
    <comment_count>0</comment_count>
    <who name="Radek Pietruszewski">radexpl</who>
    <bug_when>2019-10-26 14:01:56 -0700</bug_when>
    <thetext>All JSC C API calls create a JSLockHolder object, which… I assume has something to do with thread safety, but I&apos;m not sure if it&apos;s just meant to prevent concurrent JSC API calls, or if it&apos;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&apos;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&apos;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).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1878128</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-06-23 23:17:43 -0700</bug_when>
    <thetext>&lt;rdar://problem/95833569&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>