Re: Allow to return same NodeList object for queries like getElementsByTagName, getElementsByClassName and getElementsByName

On Feb 12, 2010, at 7:09 AM, Anne van Kesteren wrote:

> On Fri, 12 Feb 2010 14:13:57 +0100, Maciej Stachowiak  
> <mjs@apple.com> wrote:
>> On Feb 12, 2010, at 5:05 AM, Anne van Kesteren wrote:
>>> Is it really a lot of performance? Our developers are not that  
>>> convinced.
>>
>> A patch that made the change in WebKit was measured as a 20%  
>> speedup on the Dromaeo DOM Core tests in both Safari and Chrome.  
>> Calling these query methods is only a small fraction of the test,  
>> so this implies a much larger speedup to the case where  
>> getElementsBy* is called in a loop. Note also that this involved  
>> two different JavaScript engines so it's unlikely to be a quirk  
>> specific to one engine. The Gecko bug cited above also shows  
>> dramatic speedups on various tests.
>
> It would be interesting to know what exactly that test is.

I believe the subtest of Dromaeo most affected is this one, you can  
view the source if you want to see what it does: <http://dromaeo.com/tests/dom-query.html 
 >.

> Optimizing for benchmarks is not always useful :-)

Both Trident and Gecko had this optimization long before that  
particular benchmark existed.

If you look at the Mozilla bug, it reported a 2.5x speedup on tight  
loops with getElementsByTagName.

>
> Also, what happens with garbage collection? Say some isolated piece  
> of code does:
>
>  x = document.getElementsByTagName("x")
>  x.p = 2
>
> ... and then later on some other piece of code does:
>
>  y = document.getElementsByTagName("x")
>  w("p" in y)
>
> Depending on whether or not x got garbage collected you would get a  
> different result.

Indeed, that is what I cited as the one observable side effect.  
(Except the other piece of code doesn't have to happen later, it could  
be the very next line.)

To the best of my knowledge, it is not common practice to add custom  
properties to NodeLists, as opposed to Nodes, especially Elements,  
where it is fairly common practice. The fact that you can never be  
guaranteed to get the same NodeList back means

Regards,
Maciej

Received on Friday, 12 February 2010 15:54:31 UTC