<?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>278700</bug_id>
          
          <creation_ts>2024-08-26 22:29:12 -0700</creation_ts>
          <short_desc>Reduce ThreadSafeRefCounted compile time</short_desc>
          <delta_ts>2024-08-28 15:25:50 -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>Web Template Framework</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>
          
          <blocked>278821</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Gerald Squelart">g_squelart</reporter>
          <assigned_to name="Gerald Squelart">g_squelart</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2055533</commentid>
    <comment_count>0</comment_count>
    <who name="Gerald Squelart">g_squelart</who>
    <bug_when>2024-08-26 22:29:12 -0700</bug_when>
    <thetext>Found with -ftime-trace and ClangBuildAnalyzer, the top-3 &quot;templates that took longest to instantiate&quot; are:
&gt; 110395 ms (35802 times, avg 3 ms): WTF::Function&lt;void ()&gt;::Function&lt;(lambda at /Volumes/WebKit/Internal/WebKit/WebKitBuild/Debug/usr/local/include/wtf/ThreadSafeRefCounted.h:143:27), void&gt;
&gt;  76389 ms (35802 times, avg 2 ms): WTF::makeUnique&lt;WTF::Detail::CallableWrapper&lt;(lambda at /Volumes/WebKit/Internal/WebKit/WebKitBuild/Debug/usr/local/include/wtf/ThreadSafeRefCounted.h:143:27), void&gt;, (lambda at /Volumes/WebKit/Internal/WebKit/WebKitBuil...
&gt;  66481 ms (35802 times, avg 1 ms): std::make_unique&lt;WTF::Detail::CallableWrapper&lt;(lambda at /Volumes/WebKit/Internal/WebKit/WebKitBuild/Debug/usr/local/include/wtf/ThreadSafeRefCounted.h:143:27), void&gt;, (lambda at /Volumes/WebKit/Internal/WebKit/WebKitBui...

And at #25 of &quot;Template sets that took longest to instantiate&quot;:
&gt; 129369 ms (35838 times, avg 3 ms): WTF::ThreadSafeRefCounted&lt;$&gt;::deref

This is due to ThreadSafeRefCounted&lt;T, DestructionThread&gt;::deref doing a `switch` on the templated enum `DestructionThread`, and for some of them moving a lambda into a `WTF::Function`, which itself always calls WTF::makeUnique.

By changing this `switch` into a sequence of `if constexpr` blocks, it&apos;s possible to pretty much squash these big compile times out of the top-1000, only leaving a small template set taking less than 4% of the original time:
&gt;  4666 ms (2065 times, avg 2 ms): WTF::ThreadSafeRefCounted&lt;$&gt;::deref</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2055534</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-08-26 22:29:20 -0700</bug_when>
    <thetext>&lt;rdar://problem/134756505&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2055535</commentid>
    <comment_count>2</comment_count>
    <who name="Gerald Squelart">g_squelart</who>
    <bug_when>2024-08-26 22:40:28 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/32749</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2056102</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-08-28 15:25:48 -0700</bug_when>
    <thetext>Committed 282871@main (9ed2e706b2c7): &lt;https://commits.webkit.org/282871@main&gt;

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

    </bug>

</bugzilla>