<?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>314101</bug_id>
          
          <creation_ts>2026-05-05 09:38:01 -0700</creation_ts>
          <short_desc>Rework ParkingLot spinloop to reduce scheduler thrashing</short_desc>
          <delta_ts>2026-05-11 20:21:25 -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>New Bugs</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</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>
          <dependson>314267</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Marcus Plutowski">marcus_plutowski</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>commit-queue</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2207696</commentid>
    <comment_count>0</comment_count>
    <who name="Marcus Plutowski">marcus_plutowski</who>
    <bug_when>2026-05-05 09:38:01 -0700</bug_when>
    <thetext>rdar://176237718

After failing to acquire a contended lock, a thread will optimistically spin for a little while before parking itself on the ParkingLot. This is beneficial to performance because very often the lock will be freed before the waiting thread needs to park.
However, at present this loop calls sched_yield 40 times in a row. This causes two problems:
  1. It reduces the “handoff quality” of the lock, as any thread acquiring the lock is ~guaranteed to resume execution with a depressed priority
  2. It causes churn in the scheduler, especially when a large number of threads are all attempting to yield at once
Experimentally, replacing the sched_yield with an equal time spinning on an appropriate nop has broad benefits across a number of platforms, but especially for A-series chips. Any test with significant GC activity benefits, as well as tests with light contention (where threads mostly don’t make it all the way through the parking loop). However, a small number of benchmarks — particularly JS3’s `bomb-workers` — are heavily contended enough that a large number of attempts at acquiring locks will park regardless of time-to-park, meaning the entire duration of the spinloop is executed on-core. In this scenario, sched_yield has the salubrious effect of reducing wasteage by allowing the scheduler to schedule this work on e.g. an e-core, reducing the impact. Entirely removing the sched_yield leads to upwards of a 40% regression on that subtest in particular, wiping out the benefits.
The simple approach is to optimistically assume that, of those lock-acquisitions which *do* succeed in acquiring the lock during the spinloop period, most will acquire it early on. As such, we can avoid calling sched_yield until some number of iterations have passed (again, replacing it with a suitable nop-loop). Thereafter, the loop only needs to call sched_yield once every few iterations, since the priority-depression lasts for some time — and again, optimistically, we want to decrease the depression-duration that will be left if the thread does succeed in acquiring the core before the next sched_yield call.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2207703</commentid>
    <comment_count>1</comment_count>
    <who name="Marcus Plutowski">marcus_plutowski</who>
    <bug_when>2026-05-05 09:52:49 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/64278</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2208197</commentid>
    <comment_count>2</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-05-06 11:04:12 -0700</bug_when>
    <thetext>Committed 312720@main (697f0265b8f6): &lt;https://commits.webkit.org/312720@main&gt;

Reviewed commits have been landed. Closing PR #64278 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2208386</commentid>
    <comment_count>3</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2026-05-06 17:52:26 -0700</bug_when>
    <thetext>Re-opened since this is blocked by bug 314267</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2208633</commentid>
    <comment_count>4</comment_count>
    <who name="Marcus Plutowski">marcus_plutowski</who>
    <bug_when>2026-05-07 10:36:17 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/64477</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209966</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-05-11 20:21:23 -0700</bug_when>
    <thetext>Committed 313051@main (d17da45094f8): &lt;https://commits.webkit.org/313051@main&gt;

Reviewed commits have been landed. Closing PR #64477 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>