W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2015

Re: Why is querySelector much slower?

From: Glen Huang <curvedmark@gmail.com>
Date: Tue, 28 Apr 2015 14:44:55 +0800
Cc: public-webapps <public-webapps@w3.org>
Message-Id: <5DA48E0C-31EE-4979-982E-AADBEF9DDAE2@gmail.com>
To: Elliott Sprehn <esprehn@chromium.org>
But If I do getElementsByClass()[0], and LiveNodeList is immediately garbage collectable, then if I change the DOM, Blink won't traverse ancestors, thus no penalty for DOM mutation?

> On Apr 28, 2015, at 2:28 PM, Elliott Sprehn <esprehn@chromium.org> wrote:
> 
> 
> 
> On Mon, Apr 27, 2015 at 11:13 PM, Glen Huang <curvedmark@gmail.com <mailto:curvedmark@gmail.com>> wrote:
> On second thought, if the list returned by getElementsByClass() is lazy populated as Boris says, it shouldn't be a problem. The list is only updated when you access that list again.
> 
> The invalidation is what makes your code slower. Specifically any time you mutate the tree, and you have live node lists, we traverse ancestors to mark them as needing to be updated.
> 
> Blink (and likely other browsers) will eventually garbage collect the LiveNodeList and then your DOM mutations will get faster again.
>  
> 
>> On Apr 28, 2015, at 2:08 PM, Glen Huang <curvedmark@gmail.com <mailto:curvedmark@gmail.com>> wrote:
>> 
>>> Live node lists make all dom mutation slower
>>> 
>> Haven't thought about this before. Thank you for pointing it out. So if I use, for example, lots of getElementsByClass() in the code, I'm actually slowing down all DOM mutating APIs?
> 
> 
Received on Tuesday, 28 April 2015 06:45:28 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:27:31 UTC