<?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>229680</bug_id>
          
          <creation_ts>2021-08-30 12:24:17 -0700</creation_ts>
          <short_desc>REGRESSION (r272900): wpt.fyi loading performance is very slow (regressed, and slower than other browsers)</short_desc>
          <delta_ts>2021-09-06 14:12:48 -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>DOM</component>
          <version>Safari Technology Preview</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>229960</dependson>
          <blocked>148695</blocked>
    
    <blocked>221386</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Simon Fraser (smfr)">simon.fraser</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>cdumez</cc>
    
    <cc>cgarcia</cc>
    
    <cc>changseok</cc>
    
    <cc>darin</cc>
    
    <cc>esprehn+autocc</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>glenn</cc>
    
    <cc>gsnedders</cc>
    
    <cc>koivisto</cc>
    
    <cc>kondapallykalyan</cc>
    
    <cc>pdr</cc>
    
    <cc>rniwa</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1788613</commentid>
    <comment_count>0</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2021-08-30 12:24:17 -0700</bug_when>
    <thetext>Load https://wpt.fyi/results/?label=master&amp;label=experimental&amp;aligned. Scroll down and click on the link for the css/ tests. Note how long it takes to load the new page.

Before r272900: a few seconds.
After 272900: many tens of seconds.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788616</commentid>
    <comment_count>1</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2021-08-30 12:25:58 -0700</bug_when>
    <thetext>Sample shows:

 +   !   1620 WebCore::Element::dispatchMouseEvent(WebCore::PlatformMouseEvent const&amp;, WTF::AtomString const&amp;, int, WebCore::Element*, WebCore::IsSyntheticClick)  (in WebCore) + 802  [0x10814d432]
 +   !     1620 WebCore::EventDispatcher::dispatchEvent(WebCore::Node&amp;, WebCore::Event&amp;)  (in WebCore) + 4771  [0x1081683a3]
 +   !       1620 WebCore::dispatchEventInDOM(WebCore::Event&amp;, WebCore::EventPath const&amp;)  (in WebCore) + 240  [0x108168e40]
 +   !         1620 WebCore::EventTarget::fireEventListeners(WebCore::Event&amp;, WebCore::EventTarget::EventInvokePhase)  (in WebCore) + 611  [0x10816c3e3]
 +   !           1620 WebCore::EventTarget::innerInvokeEventListeners(WebCore::Event&amp;, WTF::Vector&lt;WTF::RefPtr&lt;WebCore::RegisteredEventListener, WTF::RawPtrTraits&lt;WebCore::RegisteredEventListener&gt;, WTF::DefaultRefDerefTraits&lt;WebCore::RegisteredEventListener&gt; &gt;, 1ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt;, WebCore::EventTarget::EventInvokePhase)  (in WebCore) + 428  [0x10816cb6c]
 +   !             1507 WebCore::JSEventListener::handleEvent(WebCore::ScriptExecutionContext&amp;, WebCore::Event&amp;)  (in WebCore) + 1965  [0x107e286ad]
 +   !             : 1507 WebCore::JSExecState::~JSExecState()  (in WebCore) + 214  [0x107e2c756]
 +   !             :   1507 WebCore::MicrotaskQueue::performMicrotaskCheckpoint()  (in WebCore) + 149  [0x108181d35]
 +   !             :     1507 WTF::Detail::CallableWrapper&lt;WebCore::WindowEventLoop::queueMutationObserverCompoundMicrotask()::$_0, void&gt;::call()  (in WebCore) + 71  [0x1081e6797]
 +   !             :       1507 WebCore::MutationObserver::notifyMutationObservers(WebCore::WindowEventLoop&amp;)  (in WebCore) + 2255  [0x10818844f]
 +   !             :         1507 WebCore::JSMutationCallback::handleEvent(WebCore::MutationObserver&amp;, WTF::Vector&lt;WTF::Ref&lt;WebCore::MutationRecord, WTF::RawPtrTraits&lt;WebCore::MutationRecord&gt; &gt;, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt; const&amp;, WebCore::MutationObserver&amp;)  (in WebCore) + 515  [0x10758deb3]
 +   !             :           1507 WebCore::JSCallbackData::invokeCallback(WebCore::JSDOMGlobalObject&amp;, JSC::JSObject*, JSC::JSValue, JSC::MarkedArgumentBuffer&amp;, WebCore::JSCallbackData::CallbackType, JSC::PropertyName, WTF::NakedPtr&lt;JSC::Exception&gt;&amp;)  (in WebCore) + 611  [0x107e10b33]
 +   !             :             1507 JSC::profiledCall(JSC::JSGlobalObject*, JSC::ProfilingReason, JSC::JSValue, JSC::CallData const&amp;, JSC::JSValue, JSC::ArgList const&amp;, WTF::NakedPtr&lt;JSC::Exception&gt;&amp;)  (in JavaScriptCore) + 174  [0x10bb8bdce]
 +   !             :               1507 JSC::Interpreter::executeCall(JSC::JSGlobalObject*, JSC::JSObject*, JSC::CallData const&amp;, JSC::JSValue, JSC::ArgList const&amp;)  (in JavaScriptCore) + 555  [0x10b92c81b]
 +   !             :                 1507 vmEntryToJavaScript  (in JavaScriptCore) + 216  [0x10b251326]
 +   !             :                   1501 ???  (in &lt;unknown binary&gt;)  [0x3a716bc303aa]
 +   !             :                   | 1501 ???  (in &lt;unknown binary&gt;)  [0x3a716ba2c317]
 +   !             :                   |   1499 ???  (in &lt;unknown binary&gt;)  [0x3a716be87fca]
 +   !             :                   |   + 1452 ???  (in &lt;unknown binary&gt;)  [0x3a716bc177d8]
 +   !             :                   |   + ! 1186 ???  (in &lt;unknown binary&gt;)  [0x3a716bdfa779]
 +   !             :                   |   + ! : 1186 ???  (in &lt;unknown binary&gt;)  [0x3a716ba011d8]
 +   !             :                   |   + ! :   1058 WebCore::jsNodePrototypeFunction_insertBefore(JSC::JSGlobalObject*, JSC::CallFrame*)  (in WebCore) + 392  [0x1075bb4a8]
 +   !             :                   |   + ! :   | 718 WebCore::ContainerNode::insertBefore(WebCore::Node&amp;, WebCore::Node*)  (in WebCore) + 1697  [0x1080ea671]
 +   !             :                   |   + ! :   | + 718 WebCore::HTMLElement::childrenChanged(WebCore::ContainerNode::ChildChange const&amp;)  (in WebCore) + 18  [0x10834fcb2]
 +   !             :                   |   + ! :   | +   697 WebCore::SlotAssignment::didChangeSlot(WTF::AtomString const&amp;, WebCore::ShadowRoot&amp;)  (in WebCore) + 260  [0x1081c9f24]
 +   !             :                   |   + ! :   | +   ! 364 WebCore::RenderTreeUpdater::tearDownRenderers(WebCore::Element&amp;, WebCore::RenderTreeUpdater::TeardownType, WebCore::RenderTreeBuilder&amp;)  (in WebCore) + 332  [0x108cd7f3c]
 +   !             :                   |   + ! :   | +   ! : 106 WebCore::ComposedTreeIterator::traverseNextInShadowTree()  (in WebCore) + 96  [0x1080e33a0]
 +   !             :                   |   + ! :   | +   ! : | 106 WebCore::ElementAndTextDescendantIterator::traverseNext()  (in WebCore) + 196,45,...  [0x1080e37b4,0x1080e371d,...]
 +   !             :                   |   + ! :   | +   ! : 67 WebCore::ComposedTreeIterator::traverseNextInShadowTree()  (in WebCore) + 192  [0x1080e3400]
 +   !             :                   |   + ! :   | +   ! : | 67 WebCore::HTMLSlotElement::assignedNodes() const  (in WebCore) + 64  [0x1083dd940]
 +   !             :                   |   + ! :   | +   ! : |   67 WebCore::SlotAssignment::assignedNodesForSlot(WebCore::HTMLSlotElement const&amp;, WebCore::ShadowRoot&amp;)  (in WebCore) + 353  [0x1081c6181]
 +   !             :                   |   + ! :   | +   ! : |     60 WebCore::SlotAssignment::assignSlots(WebCore::ShadowRoot&amp;)  (in WebCore) + 258  [0x1081c9032]
 +   !             :                   |   + ! :   | +   ! : |     + 34 WebCore::SlotAssignment::assignToSlot(WebCore::Node&amp;, WTF::AtomString const&amp;)  (in WebCore) + 730,340,...  [0x1081ca63a,0x1081ca4b4,...]</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788617</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-08-30 12:26:15 -0700</bug_when>
    <thetext>&lt;rdar://problem/82541045&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788649</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2021-08-30 14:01:56 -0700</bug_when>
    <thetext>&lt;rdar://81789435&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788827</commentid>
    <comment_count>4</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2021-08-31 02:12:59 -0700</bug_when>
    <thetext>hmm, this happens because a lot of elements are added to the same shadow root, so didChangeDefaultSlot() and hostChildElementDidChange() are called too many times. Iterating the composed tree every time makes things super slow. I don&apos;t think we need to tear down renderers on every didChangeSlot call, only the ones coming from hostChildElementDidChange() and not in all those cases either. IIRC the problem was only when replacing a previous tree and there was a node with display contents. So, I think we need to find a more specific solution.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788872</commentid>
    <comment_count>5</comment_count>
      <attachid>436877</attachid>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2021-08-31 05:07:13 -0700</bug_when>
    <thetext>Created attachment 436877
patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788877</commentid>
    <comment_count>6</comment_count>
      <attachid>436877</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2021-08-31 05:44:28 -0700</bug_when>
    <thetext>Comment on attachment 436877
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=436877&amp;action=review

&gt; Source/WebCore/rendering/updating/RenderTreeUpdater.cpp:544
&gt; +    if (!host.renderer() &amp;&amp; !host.hasDisplayContents())
&gt; +        return;

Oh, good catch! this is consistent with destroyRenderTreeIfNeeded().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788879</commentid>
    <comment_count>7</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2021-08-31 05:50:37 -0700</bug_when>
    <thetext>&gt; Oh, good catch! this is consistent with destroyRenderTreeIfNeeded().

This test should/could probably be in tearDownRenderers but lets do a minimal fix here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788975</commentid>
    <comment_count>8</comment_count>
      <attachid>436877</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2021-08-31 11:06:48 -0700</bug_when>
    <thetext>Comment on attachment 436877
patch

Any good way to regression-test this performance optimization? Maybe we could make a test that is *super-slow* if this is broken.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789008</commentid>
    <comment_count>9</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2021-08-31 12:03:46 -0700</bug_when>
    <thetext>&gt; Any good way to regression-test this performance optimization? Maybe we
&gt; could make a test that is *super-slow* if this is broken.

Those sort of benchmark is layout tests have often been problematic (hard to make reliable and speedy enough). We definitely should have coverage in our regular performance tests for Shadow DOM as it is getting increasingly popular. Speedometer3 is apparently planned to have some. It might also make sense to add microbenchmarks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789009</commentid>
    <comment_count>10</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2021-08-31 12:04:26 -0700</bug_when>
    <thetext>Committed r281813 (241149@main): &lt;https://commits.webkit.org/241149@main&gt;

All reviewed patches have been landed. Closing bug and clearing flags on attachment 436877.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789052</commentid>
    <comment_count>11</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2021-08-31 13:32:50 -0700</bug_when>
    <thetext>(In reply to Antti Koivisto from comment #9)
&gt; &gt; Any good way to regression-test this performance optimization? Maybe we
&gt; &gt; could make a test that is *super-slow* if this is broken.
&gt; 
&gt; Those sort of benchmark is layout tests have often been problematic (hard to
&gt; make reliable and speedy enough). We definitely should have coverage in our
&gt; regular performance tests for Shadow DOM as it is getting increasingly
&gt; popular. Speedometer3 is apparently planned to have some. It might also make
&gt; sense to add microbenchmarks.

Seems to me that this optimization for this issue is so huge, it lends itself to a fast test that would simply hang without the optimization. Maybe that’s not right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789271</commentid>
    <comment_count>12</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2021-09-01 02:14:22 -0700</bug_when>
    <thetext>Yeah, maybe. I&apos;ll try.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789365</commentid>
    <comment_count>13</comment_count>
    <who name="Sam Sneddon [:gsnedders]">gsnedders</who>
    <bug_when>2021-09-01 10:25:00 -0700</bug_when>
    <thetext>Yeah, for anything like this where we&apos;re doing &gt; O(n) work it&apos;s not too hard to write a regression test; I&apos;m against writing tests for checking whether O(n) differs from O(n), but O(n) (or O(1) in this case) versus O(n^2) is pretty easy to detect.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1790697</commentid>
    <comment_count>14</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2021-09-06 07:06:06 -0700</bug_when>
    <thetext>Perf test in 229960</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>436877</attachid>
            <date>2021-08-31 05:07:13 -0700</date>
            <delta_ts>2021-08-31 12:04:28 -0700</delta_ts>
            <desc>patch</desc>
            <filename>repeated-teardown-on-slot-change.patch</filename>
            <type>text/plain</type>
            <size>1685</size>
            <attacher name="Antti Koivisto">koivisto</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