[Fixed] In Chrome, mutation observers are not used

Posting here is no longer possible, please use the corresponding product forum.
Locked
nallar

[Fixed] In Chrome, mutation observers are not used

Post by nallar »

Adblockplus uses mutation events in Chrome, even though mutation observers have been supported for the last few versions. Mutation observers are more reliable and have better performance than mutation events, and this will definitely speed up ABP for Chrome if the swap is made.

Firefox 14 also supports mutation observers.
Wladimir Palant

Re: In Chrome, mutation observers are not used

Post by Wladimir Palant »

I was confused at first. Had to search the source code to realize that we still have that bogus "disable text ads" feature around and it still uses mutation events. I wonder whether anybody notices if I kill it...

Anyway, fixed: https://hg.adblockplus.org/adblockplusc ... a569d71eb2
nallar

Re: [Fixed] In Chrome, mutation observers are not used

Post by nallar »

You've forgotten the call to .observe, so that'll actually do nothing:

Code: Select all

.observe(document.body, {subtree: true, childList: true, characterData: true, attributes: false});
- set it to what you need, obviously.
nallar

Re: [Fixed] In Chrome, mutation observers are not used

Post by nallar »

Sorry, can't edit as I'm not registered.

Maybe you should disable that feature by default, since it will still have a performance impact with observers?

Code: Select all

var elts = document.querySelectorAll("a.IL_LINK_STYLE, a.lw_cad_link, a.cm_word, a.contextual, a.kLink, a[itxtdid], nobr, ispan, span.IL_AD");
About that, if you can find an alternative to that you probably should - querySelectorAll doesn't return a live node list, so it's actually quite slow - http://www.nczonline.net/blog/2010/09/2 ... lectorall/. Obviously some testing with jsperf to check before implementing would be a good idea too.
Wladimir Palant

Re: [Fixed] In Chrome, mutation observers are not used

Post by Wladimir Palant »

nallar wrote:You've forgotten the call to .observe, so that'll actually do nothing
Ouch. I actually tested that code and it worked - but maybe I didn't reload the extension. Fixed: https://hg.adblockplus.org/adblockplusc ... 7f33aa6e7b
nallar wrote:Maybe you should disable that feature by default, since it will still have a performance impact with observers?
Good idea, done: https://hg.adblockplus.org/adblockplusc ... 738088ac06
As I said, that's a feature that I would prefer to remove rather than spend time improving it.
Locked