W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2009

Re: Mutation events - slowness examples

From: Sean Hogan <shogun70@westnet.com.au>
Date: Sun, 7 Jun 2009 20:01:05 +0800 (WST)
To: Boris Zbarsky <bzbarsky@MIT.EDU>
Cc: www-dom@w3.org
Message-ID: <1262664738.3576831244376065293.JavaMail.root@zim-store03.web.westnet.com.au>

----- "Boris Zbarsky" <bzbarsky@MIT.EDU> wrote:

> Sean Hogan wrote: 
> > - a DOMNodeInserted listener NOT on the event chain: 1.5x
> 
> Not quite; see below.
> 
> > That doesn't seem so bad.
> 
> It does to me, for several reasons:
> 
> 1)  The "no listeners" part will keep getting smaller; as you can see
>      by comparing to Chrome and Opera, Firefox could improve this
>      part quite a bit.
> 2)  The testcase has a very shallow DOM.  The "no listeners" part
>      doesn't really depend on DOM depth much.  Event dispatch is O(N)
>      in depth of DOM, pretty much by definition.
> 3)  Even a 2x slowdown (or heck, even 1.5x) is huge.
> 

It's only huge if it noticeably affects the UX. 
This example arguably proves that it does not: 1024 DOMNodeInserted events and it's only just on the threshold of user awareness - 100ms. 
And this test doesn't even include the time for rendering - I've done some primitive testing and for a smaller number of inserted nodes (say 100) the rendering takes longer than the event dispatch. 

> > If the 1.5x for the last case could be optimized to 1.1x then I
> would say just stick with the current spec.
> 
> The main issues for me with the current spec from my point of view are
> not the perf issues when you do use mutation events, necessarily, but
> the performance impact on the no-event case forced by possible 
> synchronous firing of events, the complexity of not introducing
> security 
> bugs while implementing mutation events, and the fact that mutation 
> events aren't as useful as a non-reentrant system could be.  There are
> plenty of other things a web page can already do to fall into "slow 
> case" paths in rendering and scripting engines, and some of these are
> more widespread than mutation listeners...
> 
Agreed. I guess by current spec I mean using DOM Events as opposed to some new handling scheme. But couldn't we just change the spec so that Mutation Events are asynchronous? Is anyone relying on them being synchronous?

> > Can the dispatch algorithm check for listeners while building the
> event target chain and abort if there aren't any? 
> 
> It already does in Gecko, which is why in practice the overhead for
> the 
> "mutation listener not on parent chain" case is not quite the 1.5x
> cited 
> above.  It'd still be O(N) in depth of DOM, of course.
> 

In fact, my testing indicates there is no time difference between "DOMNodeInserted listener not on parent chain" and no DOMNodeInserted listener. Do you have examples that demonstrate otherwise? 
Received on Sunday, 7 June 2009 12:01:48 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:00 GMT