<?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>13445</bug_id>
          
          <creation_ts>2007-04-22 01:55:45 -0700</creation_ts>
          <short_desc>NodeList access by index is slow</short_desc>
          <delta_ts>2007-04-25 11:42:09 -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>523.x (Safari 3)</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.4</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.hixie.ch/tests/adhoc/perf/dom/artificial/core/001.html</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alexey Proskuryakov">ap</reporter>
          <assigned_to name="Alexey Proskuryakov">ap</assigned_to>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>13316</commentid>
    <comment_count>0</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2007-04-22 01:55:45 -0700</bug_when>
    <thetext>On the &quot;index&quot; part of this test (see bug URL), WebKit is much slower than other browsers.

On my machine, TOT is even somewhat slower than shipping Safari (~6 seconds vs. ~7 seconds), but I&apos;m hesitant to make the bug P1 because of this. Almost all of the time is spent calling nextSibling(), which is a single memory access instruction, so the test is memory-bound, and it&apos;s probably semi-random changes in memory layout that cause this.

    while (n &amp;&amp; pos &lt; index) {
        n = n-&gt;nextSibling();
        pos++;
    }

Looking at the assembly, I noticed that gcc 3.3 and gcc 4.0.1 generate slightly different PowerPC code for this loop. That doesn&apos;t appear to affect performance much - I made a reduced test, and gcc 4 code was not slower.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12974</commentid>
    <comment_count>1</comment_count>
      <attachid>14161</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2007-04-24 13:31:58 -0700</bug_when>
    <thetext>Created attachment 14161
easy way out

Just add support for iterating backwards. On my machine, results on the &quot;Index&quot; test look OK now (~7000 ms TOT, ~100 ms TOT + this patch, ~120 ms Opera, ~1300 ms Firefox).

KHTML also has support for iterating backwards, and according to Maks Orlovich, it was added to fix a real site, forums.tweakers.nl. I&apos;ve also added support for iteration from lastChild.

I still think that there might be a better data structure for a list of child nodes in ContainerNode, and that would speed up other operations, too. Obviously, performance of data structures is always a trade-off, so it would probably take someone with access to PLT to play with it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12756</commentid>
    <comment_count>2</comment_count>
      <attachid>14161</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2007-04-25 01:04:25 -0700</bug_when>
    <thetext>Comment on attachment 14161
easy way out

+        unsigned dist = (unsigned)abs((long)index - (long)m_caches-&gt;lastItemOffset);

Since the parameter to abs is an int, the cast here should be to int, not long. But also no casts are needed. If you do unsigned - unsigned, then pass to int, and then extract it into unsigned it will do the right thing with no casts at all.

Otherwise looks fine. r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>12499</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2007-04-25 11:42:09 -0700</bug_when>
    <thetext>Ah, I got confused by std::abs from cstdlib. Hoping MSVC won&apos;t be confused similarly :-).

Committed revision 21090.
</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>14161</attachid>
            <date>2007-04-24 13:31:58 -0700</date>
            <delta_ts>2007-04-25 01:04:25 -0700</delta_ts>
            <desc>easy way out</desc>
            <filename>13445r1_patch.txt</filename>
            <type>text/plain</type>
            <size>2744</size>
            <attacher name="Alexey Proskuryakov">ap</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiAyMTA3MikKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMTUgQEAKKzIwMDctMDQtMjUgIEFsZXhleSBQcm9za3VyeWFrb3YgIDxhcEB3ZWJr
aXQub3JnPgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAg
IGh0dHA6Ly9idWdzLndlYmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTEzNDQ1CisgICAgICAgIE5v
ZGVMaXN0IGFjY2VzcyBieSBpbmRleCBpcyBzbG93CisKKyAgICAgICAgKiBkb20vQ2hpbGROb2Rl
TGlzdC5jcHA6CisgICAgICAgIChXZWJDb3JlOjpDaGlsZE5vZGVMaXN0OjppdGVtKTogU3VwcG9y
dCBpdGVyYXRpbmcgYmFja3dhcmRzIGZyb20gdGhlIGxhc3QgYWNjZXNzZWQgbm9kZQorICAgICAg
ICBvciBmcm9tIHRoZSBsYXN0IGNoaWxkLgorICAgICAgICAqIGRvbS9Ob2RlTGlzdC5oOiBNYWtl
IGNhY2hlZExlbmd0aCB1bnNpZ25lZC4KKwogMjAwNy0wNC0yNCAgRGFyaW4gQWRsZXIgIDxkYXJp
bkBhcHBsZS5jb20+CiAKICAgICAgICAgUmV2aWV3ZWQgYnkgSnVzdGluLgpJbmRleDogV2ViQ29y
ZS9kb20vQ2hpbGROb2RlTGlzdC5jcHAKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT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CiAKLSAgICB3aGlsZSAobiAmJiBwb3MgPCBp
bmRleCkgewotICAgICAgICBuID0gbi0+bmV4dFNpYmxpbmcoKTsKLSAgICAgICAgcG9zKys7Cisg
ICAgaWYgKG1fY2FjaGVzLT5pc0xlbmd0aENhY2hlVmFsaWQpIHsKKyAgICAgICAgaWYgKGluZGV4
ID49IG1fY2FjaGVzLT5jYWNoZWRMZW5ndGgpCisgICAgICAgICAgICByZXR1cm4gMDsKKworICAg
ICAgICB1bnNpZ25lZCBkaXN0ID0gKHVuc2lnbmVkKWFicygobG9uZylpbmRleCAtIChsb25nKXBv
cyk7CisgICAgICAgIGlmIChkaXN0ID4gbV9jYWNoZXMtPmNhY2hlZExlbmd0aCAtIDEgLSBpbmRl
eCkgeworICAgICAgICAgICAgbiA9IG1fcm9vdE5vZGUtPmxhc3RDaGlsZCgpOworICAgICAgICAg
ICAgcG9zID0gbV9jYWNoZXMtPmNhY2hlZExlbmd0aCAtIDE7CisgICAgICAgIH0KICAgICB9CiAK
KyAgICBpZiAocG9zIDw9IGluZGV4KQorICAgICAgICB3aGlsZSAobiAmJiBwb3MgPCBpbmRleCkg
eworICAgICAgICAgICAgbiA9IG4tPm5leHRTaWJsaW5nKCk7CisgICAgICAgICAgICArK3BvczsK
KyAgICAgICAgfQorICAgIGVsc2UKKyAgICAgICAgd2hpbGUgKG4gJiYgcG9zID4gaW5kZXgpIHsK
KyAgICAgICAgICAgIG4gPSBuLT5wcmV2aW91c1NpYmxpbmcoKTsKKyAgICAgICAgICAgIC0tcG9z
OworICAgICAgICB9CisKICAgICBpZiAobikgewogICAgICAgICBtX2NhY2hlcy0+bGFzdEl0ZW0g
PSBuOwogICAgICAgICBtX2NhY2hlcy0+bGFzdEl0ZW1PZmZzZXQgPSBwb3M7CkluZGV4OiBXZWJD
b3JlL2RvbS9Ob2RlTGlzdC5oCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvZG9tL05vZGVMaXN0LmgJ
KHJldmlzaW9uIDIxMDcwKQorKysgV2ViQ29yZS9kb20vTm9kZUxpc3QuaAkod29ya2luZyBjb3B5
KQpAQCAtNDIsNyArNDIsNyBAQCBwdWJsaWM6CiAgICAgICAgIENhY2hlcygpOwogICAgICAgICB2
b2lkIHJlc2V0KCk7CiAgICAgICAgIAotICAgICAgICBpbnQgY2FjaGVkTGVuZ3RoOworICAgICAg
ICB1bnNpZ25lZCBjYWNoZWRMZW5ndGg7CiAgICAgICAgIE5vZGUqIGxhc3RJdGVtOwogICAgICAg
ICB1bnNpZ25lZCBsYXN0SXRlbU9mZnNldDsKICAgICAgICAgYm9vbCBpc0xlbmd0aENhY2hlVmFs
aWQgOiAxOwo=
</data>
<flag name="review"
          id="5747"
          type_id="1"
          status="+"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>