Is the performance impact of DOM Mutation events limited to the document?

Showing 1-4 of 4 messages
Is the performance impact of DOM Mutation events limited to the document? Jorge Villalobos 3/28/12 1:06 PM
Hello all,

As many of you know, adding DOM Mutation event listeners can lead to a
significant performance penalty, which is why better alternatives are
being worked on (bug 641821).

In the meantime, we tolerate extensions to use them as long as they are
considered necessary for their functioning and they are limited to
content documents. We base the second requirement in the assumption that
adding DOM Mutation listeners to a content document don't affect the
performance of the main XUL window, and the performance penalty is
limited to the document and will disappear once the document is destroyed.

One add-on developer claims that this isn't the case:

https://forums.mozilla.org/addons/viewtopic.php?f=7&t=3180

He says that adding a DOM Mutation listener on any document affects the
whole browser window permanently. Is this correct? If so, we'll need to
revisit our policies around these listeners.

Thanks,

- Jorge
Re: Is the performance impact of DOM Mutation events limited to the document? smaug 3/28/12 1:48 PM
No.
The mutation event related flags are per (content or chrome) JS window
object, and the flags are set to inner window, not to outer window.
I don't know where iann got the idea that flags are in the outer window,
and even in that case using mutation event listeners for
content pages wouldn't really affect to chrome.


-Olli
Re: Is the performance impact of DOM Mutation events limited to the document? Justin Dolske 3/28/12 6:10 PM
On 3/28/12 1:48 PM, smaug wrote:

>> https://forums.mozilla.org/addons/viewtopic.php?f=7&t=3180
>>
>> He says that adding a DOM Mutation listener on any document affects the
>> whole browser window permanently. Is this correct?
> No.
> The mutation event related flags are per (content or chrome) JS window
> object, and the flags are set to inner window, not to outer window.
> I don't know where iann got the idea that flags are in the outer window,
> and even in that case using mutation event listeners for
> content pages wouldn't really affect to chrome.

I just skimmed the thread, but I think you're both right because the
terminology in the thread is a little vague. :)

The flag(s?) may be on the inner-window, but I _think_ what that person
was talking about was that once set, they persist for the lifetime of
that window (window the JS global, not window the user interface). ISTR
having heard the same -- even if you remove a mutation listener,
performance of that page's DOM will continue to be crappy. Is this still
true?

[And so the worst-case fear would be an add-on that adds a mutation
listener at every page load. Even if it quickly removes the listener, it
would see as if every page was always slow.]

Justin
Re: Is the performance impact of DOM Mutation events limited to the document? Boris Zbarsky 3/28/12 6:37 PM
On 3/28/12 6:10 PM, Justin Dolske wrote:
> The flag(s?) may be on the inner-window, but I _think_ what that person
> was talking about was that once set, they persist for the lifetime of
> that window (window the JS global, not window the user interface). ISTR
> having heard the same -- even if you remove a mutation listener,
> performance of that page's DOM will continue to be crappy. Is this still
> true?

Yes, this is correct.  More precisely, performance for the operations
that would have fired that listener will continue to be pretty crappy.

-Boris