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

Re: Mutation events - slowness examples

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Sat, 06 Jun 2009 21:11:36 -0400
Message-ID: <4A2B13C8.2090201@mit.edu>
To: Sean Hogan <shogun70@westnet.com.au>
CC: www-dom@w3.org
Sean Hogan wrote:
> Interesting. I may not be reading these results correctly - could you confirm these ratios:
> - no listeners: 1x
> - a DOMNodeInserted listener on the event chain: 2x (not counting listener execution time)

This is correct, in a current trunk Firefox build, on this particular 
testcase.  The ratio was much higher in Opera and Chrome.

> - 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.

> 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...

Those whose concern are the in-page impact of actually using a mutation 
listener should feel free to post their own thoughts on the numbers 
here, of course.

> 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.

-Boris
Received on Sunday, 7 June 2009 01:12:21 GMT

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