<?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>76003</bug_id>
          
          <creation_ts>2012-01-10 15:54:24 -0800</creation_ts>
          <short_desc>REGRESSION (r104210): WebProcess spins at 100% CPU for several minutes when loading an internal Apple site</short_desc>
          <delta_ts>2012-01-10 23:11:02 -0800</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>528+ (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, Regression</keywords>
          <priority>P1</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>76032</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Mark Rowe (bdash)">mrowe</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>kling</cc>
    
    <cc>koivisto</cc>
    
    <cc>oliver</cc>
    
    <cc>rniwa</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>533441</commentid>
    <comment_count>0</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2012-01-10 15:54:24 -0800</bug_when>
    <thetext>After r104210 we&apos;re seeing WebProcess spin at 100% CPU for several minutes after loading pages on an internal Apple site. A sample shows that almost all of the time is being spent in DynamicSubtreeNodeList::length below calls to WebCore::JSNodeList::getOwnPropertySlotByIndex.  I&apos;ll attach a reduction that demonstrates the regression.

&lt;rdar://problem/10672251&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533443</commentid>
    <comment_count>1</comment_count>
      <attachid>121927</attachid>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2012-01-10 15:55:37 -0800</bug_when>
    <thetext>Created attachment 121927
Reduction (may hang your browser for 30+ seconds!)

This reduction demonstrates the issue. The iteration step took ~200ms pre-r104210 but now takes around 30 seconds.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533506</commentid>
    <comment_count>2</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 17:18:55 -0800</bug_when>
    <thetext>(In reply to comment #0)
&gt; After r104210 we&apos;re seeing WebProcess spin at 100% CPU for several minutes after loading pages on an internal Apple site. A sample shows that almost all of the time is being spent in DynamicSubtreeNodeList::length below calls to WebCore::JSNodeList::getOwnPropertySlotByIndex.  I&apos;ll attach a reduction that demonstrates the regression.

According to my research people rarely modified DOM while hanging onto node list. This regression is the most pathological case where you&apos;re looping over node list and modifying DOM.

I suppose such code wasn&apos;t as unusual as I initially thought but you can get the same hang even before r104210 if you had modified the class name of any element inside the loop; e.g. element.className = &apos;hide&apos;;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533560</commentid>
    <comment_count>3</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 18:40:06 -0800</bug_when>
    <thetext>Oh man... JSNodeList::getOwnPropertySlotByIndex is always calling NodeList::length() before calling NodeList::item(). This would mean that we&apos;ll end up iterating through the entire subtree whenever we call DynamicSubtreeNodeList::item from JavaScript unless the length is cached :(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533562</commentid>
    <comment_count>4</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 18:45:56 -0800</bug_when>
    <thetext>Could you tell me what getOwnPropertySlotByIndex is doing and if there&apos;s way to avoid calling length there?

I&apos;m guessing that we just need to verify that the specified index exists. Is that right? In that case, we can probably add new methods like isIndexValid(unsigned) that only looks for the specified index.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533580</commentid>
    <comment_count>5</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2012-01-10 19:30:04 -0800</bug_when>
    <thetext>Perhaps I&apos;m missing something, but how would isIndexValid help? It seems as though you&apos;d still have to walk over the subtree in order to return an answer.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533609</commentid>
    <comment_count>6</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2012-01-10 20:58:39 -0800</bug_when>
    <thetext>(In reply to comment #2)
&gt; (In reply to comment #0)
&gt; &gt; After r104210 we&apos;re seeing WebProcess spin at 100% CPU for several minutes after loading pages on an internal Apple site. A sample shows that almost all of the time is being spent in DynamicSubtreeNodeList::length below calls to WebCore::JSNodeList::getOwnPropertySlotByIndex.  I&apos;ll attach a reduction that demonstrates the regression.
&gt; 
&gt; According to my research people rarely modified DOM while hanging onto node list. This regression is the most pathological case where you&apos;re looping over node list and modifying DOM.
&gt; 
&gt; I suppose such code wasn&apos;t as unusual as I initially thought but you can get the same hang even before r104210 if you had modified the class name of any element inside the loop; e.g. element.className = &apos;hide&apos;;

To me it seems like a fairly obvious pattern to get a nodelist and then iterate over that list modifying attributes.  This seems like a fairly significant reason for them to exist at all.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533637</commentid>
    <comment_count>7</comment_count>
      <attachid>121977</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 22:14:19 -0800</bug_when>
    <thetext>Created attachment 121977
reduction for pre r104210

(In reply to comment #6)
&gt; To me it seems like a fairly obvious pattern to get a nodelist and then iterate over that list modifying attributes.  This seems like a fairly significant reason for them to exist at all.

According to my study on the bug 73853, this accounts for less than 1% of the real world usage of node list API. Also this behavior existed prior to r104210 as well. You just need to touch the right attribute.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533639</commentid>
    <comment_count>8</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 22:20:26 -0800</bug_when>
    <thetext>If we want to optimize for this case and keep caches as long as we can, then we should completely abandon (revert) the approach took in r104263.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533643</commentid>
    <comment_count>9</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2012-01-10 22:24:28 -0800</bug_when>
    <thetext>I don&apos;t agree with your retitling of this bug. It hides the most important fact here: that the change in r104210 broke a real-world website.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533644</commentid>
    <comment_count>10</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 22:27:38 -0800</bug_when>
    <thetext>(In reply to comment #9)
&gt; I don&apos;t agree with your retitling of this bug. It hides the most important fact here: that the change in r104210 broke a real-world website.

I knew I was regressing the performance on some websites as a trade off, and the example I gave here demonstrates that the same behavior can be replicated prior to r104210. I don&apos;t think I need to demonstrate the fact some websites would be hitting the case I posted.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533645</commentid>
    <comment_count>11</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 22:30:32 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; Perhaps I&apos;m missing something, but how would isIndexValid help? It seems as though you&apos;d still have to walk over the subtree in order to return an answer.

At least then we wouldn&apos;t have to traverse through the entire subtree on every iteration of the loop.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533647</commentid>
    <comment_count>12</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2012-01-10 22:33:09 -0800</bug_when>
    <thetext>(In reply to comment #10)
&gt; (In reply to comment #9)
&gt; &gt; I don&apos;t agree with your retitling of this bug. It hides the most important fact here: that the change in r104210 broke a real-world website.
&gt; 
&gt; I knew I was regressing the performance on some websites as a trade off, and the example I gave here demonstrates that the same behavior can be replicated prior to r104210. I don&apos;t think I need to demonstrate the fact some websites would be hitting the case I posted.

Existing websites are much less likely to be doing something along the lines of your posted example because it already had terrible performance in shipping versions of WebKit. Existing websites could easily be doing something along the lines of the reduction because until r104210 it was sufficiently fast.

When your trade-off makes code that formerly ran in O(N) time now run in O(N ** 2) time, perhaps it&apos;s not the right one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533651</commentid>
    <comment_count>13</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 22:36:59 -0800</bug_when>
    <thetext>(In reply to comment #12)
&gt; Existing websites are much less likely to be doing something along the lines of your posted example because it already had terrible performance in shipping versions of WebKit. Existing websites could easily be doing something along the lines of the reduction because until r104210 it was sufficiently fast.
&gt;
&gt; When your trade-off makes code that formerly ran in O(N) time now run in O(N ** 2) time, perhaps it&apos;s not the right one.

I completely disagree with either one of your points but I&apos;m rolling out r104210 anyway to improve the node lists performance.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533665</commentid>
    <comment_count>14</comment_count>
      <attachid>121927</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-10 23:05:33 -0800</bug_when>
    <thetext>Comment on attachment 121927
Reduction (may hang your browser for 30+ seconds!)

Now that the patch has been rolled out in http://trac.webkit.org/changeset/104674, this reduction is obsolete.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>533666</commentid>
    <comment_count>15</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2012-01-10 23:06:27 -0800</bug_when>
    <thetext>Thanks for fixing this issue.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>121927</attachid>
            <date>2012-01-10 15:55:37 -0800</date>
            <delta_ts>2012-01-10 23:06:59 -0800</delta_ts>
            <desc>Reduction (may hang your browser for 30+ seconds!)</desc>
            <filename>rdar-10672251.html</filename>
            <type>text/html</type>
            <size>1197</size>
            <attacher name="Mark Rowe (bdash)">mrowe</att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pb24gcnVuVGVzdCgp
CnsKICAgIHZhciBzdGFydCA9ICtuZXcgRGF0ZSgpOwoKICAgIHZhciBub2RlTGlzdCA9IGRvY3Vt
ZW50LmdldEVsZW1lbnRzQnlDbGFzc05hbWUoInRlc3QiKTsKICAgIGZvciAodmFyIGkgPSAwLCBj
b3VudCA9IG5vZGVMaXN0Lmxlbmd0aDsgaSA8IGNvdW50OyArK2kpIHsKICAgICAgICB2YXIgZWxl
bWVudCA9IG5vZGVMaXN0W2ldOwogICAgICAgIGVsZW1lbnQuc2V0QXR0cmlidXRlKCdzdHlsZScs
ICJkaXNwbGF5OiBub25lIik7CiAgICB9CgogICAgbG9nKCdJdGVyYXRpbmcgYW5kIHNldHRpbmcg
dGhlaXIgc3R5bGUgdG8gZGlzcGxheTpub25lIHRvb2sgJyArICgrKG5ldyBEYXRlKCkpIC0gc3Rh
cnQpICsgJ21zJyk7Cn0KCiAgICBpbml0aWFsaXplKCk7CgogICAgPC9zY3JpcHQ+CjwvYm9keT4K
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>121977</attachid>
            <date>2012-01-10 22:14:19 -0800</date>
            <delta_ts>2012-01-10 22:14:19 -0800</delta_ts>
            <desc>reduction for pre r104210</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>1186</size>
            <attacher name="Ryosuke Niwa">rniwa</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgogICAgPG1ldGEgY2hhcnNldD0idXRmLTgiPgo8L2hlYWQ+Cjxib2R5Pgog
ICAgPGRpdiBpZD0ibG9nIj48L2Rpdj4KICAgIDxzY3JpcHQ+CgpmdW5jdGlvbiBsb2cobWVzc2Fn
ZSkKewogICAgdmFyIG1lc3NhZ2VFbGVtZW50ID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgncCcp
OwogICAgbWVzc2FnZUVsZW1lbnQuYXBwZW5kQ2hpbGQoZG9jdW1lbnQuY3JlYXRlVGV4dE5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KTsKICAgIH0KCiAgICBsb2coJ0l0ZXJhdGluZyBhbmQgc2V0dGluZyB0aGVpciBzdHls
ZSB0byBkaXNwbGF5Om5vbmUgdG9vayAnICsgKCsobmV3IERhdGUoKSkgLSBzdGFydCkgKyAnbXMn
KTsKfQoKICAgIGluaXRpYWxpemUoKTsKCiAgICA8L3NjcmlwdD4KPC9ib2R5Pg==
</data>

          </attachment>
      

    </bug>

</bugzilla>