Thursday, July 21, 2016

AdBlock - The browser killer

TLDR; This is not an anti-adblock post. The AdBlock extension is a proved CPU eater and it is proved that the AdBlock extension slows down your browsing experiences. I and many other devs suggest you "Ublock Origin" extension. Ublock Origin is fast and it has less bugs.

We had a CPU usage issue for a while ago with AdBlock users on reported by some of our users.

At first we thought that this CPU problem is about user's system resources and we didn't mind too much.
After a while we started to get too many complaints about same issue. We dig into this then we saw that this is a problem about AdBlock extension. Yes the most popular ad-blocker extension in Webstore.

Here is a profile result for with a Chrome browser + Adblock extension

The CPU killer function named addElemHideSelectors is a core function of Adblock. We searched about this function and we saw that this issue has been already reported on AdblockPlus Trac (not Adblock, AdBlock Plus) [1] [2] has been already fixed this by a very few code changes. [3]

So I reported the same issue on (which is a closed ticket system, where no one sees your ticket or process of the fix.) [4]

Then for long time we got no response. Even an automated response. We dig again and reviewed the Adblock source code. We focused on the problematic function and it's calls. [5]

We saw that there is too many array operations while collecting "something" with string match "source" and "track", and we have too many "data-track" and data-tracksource" and "data-source" attributes on our website. So we replaced these attributes with abbreviations  like data-trck or data-trcksrc. After this change immediately AdBlock problematic function's CPU usage decreased from %60 to %30.  See it from my second CPU profiling result

But we still didn't solve the CPU issue. We just relaxed our users a little.
It is sad that we should be Adblock compatible.

We then applied the patch that AdblockPlus have made to Adblock. Ad here is the result. The only problem is that Adblock iterating 172K size array without grouping and immediately.

Iterating array with groups and using slice instead of splice solves this problem. 

"The problem seems to be caused by ​the while loop inside addElemHideSelectors somehow." noted on AdBlock Plus trac page 
As a result we are struggling with AdBlock issues because they have very slow development processes or they develop nothing. If you really want an adblocker extension try Ublock Origin. It is fast. If you want an adblock extension that has "adblock" in it's name try Adblock Plus. But don't use  "AdBlock".  Popular doesn't mean it's the best.

1. Adblock and AdblockPlus is different projects but they share common libraries. 
2. The issue reported on AdblockPlus
3. Fix for the issue on AdblockPlus repo
4. AdBlock ticket system
5. The js file of AdbBlock that we analyzed

Update from my mentions to @getadblocker

Update #2
After Adblock released it's 3.1 version our pains are gone.


Rhana Cassidy said...

Hi, I'm Rhana Cassidy, Community Manager for AdBlock. I'm also the lone member of the AdBlock Support team. I've been playing catch-up with new tickets on our help desk. That's why you didn't get a response from us. Not an excuse, just an explanation.

We discovered the huge performance hit shortly after our major upgrade to AdBlock 3.0 was released. We immediately investigated, found the code that was causing it, and fixed it. It's been in quality review ever since, so that AdBlock 3.1 will have zero issues.

AdBlock 3.1 will be twice as fast as AdBlock 3.0. We're hoping to be able to release it by next week. Please hang in there! We think you'll be pleased with the results. :)

Hasan Tayyar BEŞİK said...

@Rhana, thank you for explanation.
Bu I feel very disappointed with AdBlock for a long time. I hope I will feel better for AdBlock after your release : )

Rhana Cassidy said...

Hasan, I hope so too. :) (There, I spelled your name correctly this time!)