Opened 3 years ago

Last modified 18 months ago

#4060 new defect

Adblock Plus for Chrome adds 50ms to DOMContentLoaded

Reported by: skillbill Assignee:
Priority: Unknown Milestone:
Module: Platform Keywords:
Cc: sebastian, kzar, mapx Blocked By:
Blocking: Platform: Chrome
Ready: no Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

Description (last modified by kzar)

How to reproduce

  1. Create a file index.html with the following contents:
<html>
  <head>
    <title>Test</title>
  </head>
  <body><h1>Test</h1></body>
</html>
  1. Launch a webserver python -m SimpleHttpServer
  2. Browse to http://localhost:8000/
  3. Open the dev tools, on the Network tab
  4. Refresh the page

Observed behaviour

A delay of around 50ms between localhost returning the document and DOMContentLoaded.

Expected behaviour

No such delay, as when Adblock Plus is uninstalled.

Notes

The delay seems to be the same when Adblock Plus has EasyList enabled as when it has no filters or subscriptions. The delay also seems the same before the changes we made for #235. The delay is present quite far back in the code (tested back to Adblock Plus 1.9), it does not seem to be a recent regression.

Change History (13)

comment:1 Changed 3 years ago by mapx

  • Cc sebastian kzar trev added

comment:2 Changed 3 years ago by mapx

  • Cc mapx added

comment:3 Changed 3 years ago by kzar

I just tried to reproduce this, hosting the following page using python -m SimpleHttpServer:

<html>
  <head>
    <title>Test</title>
  </head>
  <body><h1>Test</h1></body>
</html>

My results:

Around 10ms with no extensions
Around 60ms with EasyList before #235 changes
Around 60ms with EasyList after #235 changes
Around 60ms with no filters/subscriptions after #235 changes

FWIW I had something like 150ms with all the extensions I normally have enabled.

According to the Chrome dev tools Network tab the response returning index.html took 4ms and then DOMContentLoaded was at 57ms, with nothing showing in between.

I was using Chrome Version 50.0.2661.94 (64-bit) on Debian Stretch.

comment:4 Changed 3 years ago by kzar

  • Component changed from Unknown to Platform
  • Description modified (diff)
  • Summary changed from 100ms + to dom content loaded to Adblock Plus for Chrome adds 50ms to DOMContentLoaded

comment:5 Changed 3 years ago by kzar

  • Description modified (diff)

comment:7 Changed 3 years ago by kzar

No, does not seem to be caused by #3699. I get pretty much the same delay before that change and indeed way before then. I tested up to 1.9, does not seem to be a recent regression.

Not to say that it's impossible to improve, perhaps there is a way. I think Sebastian is more likely to have some ideas there though.

comment:8 Changed 3 years ago by kzar

  • Description modified (diff)

comment:9 Changed 3 years ago by sebastian

I can confirm that Adblock Plus is adding some overhead to page load, even with no active filters or even when commenting out the element hiding code. However, this behavior isn't specific to Adblock Plus but all extensions that use content scripts seem to cause a delay. For reference I get ~15ms with no extension, ~100ms with Adblock Plus and ~60ms with uBlock.

The reason why Adblock Plus is causing more delay than other extensions might be that we have 3 content scripts that run at document_start. And there is certainly some overhead per script regardless of the code that the script runs. For reference, when I remove any code from all of our content scripts it still takes ~35ms to load the page. So perhaps we can reduce the overhead by bundling all 3 content scripts into a single file.

Besides that, we can also try moving include.postload.js from document_end to document_idle. Theoretically, this shouldn't have any effect on DOMContentLoaded, but in my tests the code in that script was repsonsible for ~10ms of the delay. And having that code run a little later if the browser is busy shouldn't hurt.

Version 1, edited 3 years ago by sebastian (previous) (next) (diff)

comment:10 Changed 3 years ago by mapx

probably the impact of the 3 content scripts is why on chrome start ABP is not able to act before the home page loading (I mean the page / pages are loaded with ads). In ubo (at least on 1 home page) the ads are correctly blocked / hidden.

comment:11 Changed 3 years ago by kzar

So perhaps we can reduce the overhead by bundling all 3 content scripts into a single file.
Besides that, we can also try moving include.postload.js from document_end to document_idle.

I tried doing both by just manually editing the extension after it was built, didn't seem much/any difference in the delay :(

comment:13 Changed 18 months ago by fhd

  • Cc trev removed
Note: See TracTickets for help on using tickets.