uBlock-LLC / uBlock

uBlock: a fast, lightweight, and lean blocker for Chrome, Firefox, and Safari.
https://ublock.org/
GNU General Public License v3.0
8.18k stars 436 forks source link

[Firefox] Slow startup when compared to AdBlock Plus #520

Closed ekerazha closed 9 years ago

ekerazha commented 9 years ago

When you start Firefox, by default the "about:home" page is loaded.

ABP and uBlock use the same lists.

This only happens when I start Firefox, if I open "about:home" afterwards it loads fast.

I didn't try other home page URLs, just about:home.

gorhill commented 9 years ago

Some observations:

Now that said, here is another case to test:

So it appears ABP is delaying the loading of its filters. However, this results in many unhappy users.

For uBlock, I do not feel the need to delay loading the filters because:

  1. it's relatively fast
  2. once a selfie is made, there won't be noticeable delay

And in both cases whatever ads will be blocked just fine on whatever tab is opened.

So the delay will go away as soon as uBlock makes a selfie of itself. More about this here.

Still, I have been thinking about further improving the loading/parsing of filter lists lately, and there might be some ideas which are worth exploring in the medium term.

harshanvn commented 9 years ago

Also, it is important to note that the startup time may vary on many other factors like...

Here is quick rundown of startup times, not sure if a selfie is a created here or not...(captured in ms, from health report)

run 1:below, opened 3 times (disabled uBlock,no addon) 1595, 853, 1071 run 2:below, opened 3 times (enabled uBlock) 839, 996, 889 run 3:below, below opened 4 times (disabled uBlock, no Addons) 867, 968, 830, 819 run 4:below, below opened 5 times (enabled uBlock) 864, 1019, 902, 894, 888

Personally i don't mind in delaying for another second or two, instead of slipping the ads and other when sites are loaded during start up.

What the important thing here is, it should not hinder the loading performance in anyway, which uBlock does it best than anything else :+1: And happy to be back as a firefox user :)

gorhill commented 9 years ago

Where did you get these numbers? They are ms I presume? Why is there more than one figure? Is it multiple measurements for the measured scenario?

harshanvn commented 9 years ago

Yes. Each number denotes one start up time. So, 3-4 times i did started the browser and repeated it 4 tmes. Path: about:healthreport --> Select Raw Data, JSON format ( search with "firstpaint", you should the see time stamps as milli seconds listed by "days")

ekerazha commented 9 years ago

At the moment uBlock doesn't slow down the home page loading anymore, maybe it uses the "selfie" now. However the slowdown was subtle but annoying when I installed the extension.

ghost commented 9 years ago

As gorhill pointed out, ABP, as of recently, loads filters after start up. On the systems I use, this helped the start up time, but makes the browser unresponsive for a few seconds. Not to mention the loss of blocking which is annoying if someone uses another website for home page besides about:home.

Adguard behaves in a similar fashion, appears to delay loading.

In other words, placebo.

Both sides of startup should be critically explored. There is no free lunch.

gorhill commented 9 years ago

the slowdown was subtle but annoying when I installed the extension

That's the thing, no free lunch: we have to choose between instant load or not blocking ads on already opened tab.

ABP chose instant load/delayed blocking, I will go with delayed load/instant blocking, given that eventually it will be instant load/instant blocking once a selfie is present.

I will still want to look into improving further the load performance though.

gorhill commented 9 years ago

I think I will work on these load speed improvement ideas, they look more and more attractive to me, and they take care of one aspect of the selfie which bothers me a lot: a selfie is a all or nothing solution, i.e. uBlock loads virtually instantly when there is a selfie, or delayed when there is no selfie. Simply adding a single custom filter invalidate the whole selfie. This bothers me.

I have in mind a solution that is more granular, and which can produce immediate results after the first install, and depending on result, maybe good enough to remove the need for selfie code.

gorhill commented 9 years ago

To give a different perspective on the "Slow startup when compared to AdBlock Plus" statement:

https://www.youtube.com/watch?v=BpypOeK10N8

gorhill commented 9 years ago

Related: #498.

gorhill commented 9 years ago

This is just dev notes for myself.

Default filter lists.

Network filters:

Cosmetic filters:

gorhill commented 9 years ago

Edit: New, more realistic benchmarks available at the bottom, now measuring timings for real browser launch, as opposed to merely disabling/enabling the extension. Also, only one "New tab" page is now used (I don't think this was the case here).

gorhill commented 9 years ago

Edit: New, more realistic benchmarks available at the bottom, now measuring timings for real browser launch, as opposed to merely disabling/enabling the extension. Also, only one "New tab" page is now used (I don't think this was the case here).


This improvement will also benefit when filter lists have to be reloaded for various other reasons than just at launch: for example, changing selection of filter lists, modifying custom filters, reload following the auto-update of filter lists (the compilation will occur when the new version is received, not when the reload occurs).

Bottom line, if there is a compiled version of a filter list, it loads faster. The cost of compiling a filter list is paid once, when the filter list is written to, and this cost is fully paid back starting at the second reload of the same filter list.

AlexVallat commented 9 years ago

I'm quite curious as to why Firefox is slower than Chromium in these tests - could you share what you are using for the benchmarking? Is it just logging a timestamp before and after µBlock.load(); in start.js?

gorhill commented 9 years ago

https://github.com/gorhill/uBlock/blob/master/src/js/profiler.js

I wrap all the code in start.js:

// Load all: executed once.

(function() {

quickProfiler.start('start.js');

Then in onAllReady(), before vAPI.onLoadAllCompleted():

quickProfiler.stop(0);
gorhill commented 9 years ago

@chrisaljoudi can we change the storage quota on Safari to be more in line with the one for Firefox? (~100 MB). Just to err on the safe side.

chrisaljoudi commented 9 years ago

@gorhill done in ed5891d876.

gorhill commented 9 years ago

Going to be running realistic benchmarks, i.e. really launching the browsers, as opposed to merely disabling/enabling the extension.

chrisaljoudi commented 9 years ago

@gorhill just as an interesting datapoint, with 0.8.8.5-dev, the average of 10 samples on Safari is 207ms.

gorhill commented 9 years ago

@chrisaljoudi The figures have to come from the same system to be able to compare them. Also, did you ensure that it's not the selfie which was loading? I made sure this was not the case with a breakpoint or a console message before starting to collect timing figures.

chrisaljoudi commented 9 years ago

@gorhill yep, I understand and you're obviously right about the figures having to come from the same system.

As far as the selfie goes, yes — I clear vAPI.storage every time.

I only wanted to share the figure because it was interesting, not for precise statistical significance.

gorhill commented 9 years ago

What's your system specs?

chrisaljoudi commented 9 years ago

@gorhill

2GHz Intel Core i7 8GB 1600MHz RAM 256GB SSD

gorhill commented 9 years ago

@chrisaljoudi 207 ms is quite fast. If ever you also measure the timings for 0.8.8.3, I will include it in the tables with a note about different system. If you checkout 0.8.8.3, you will have to add the code for profiling in start.js.

gorhill commented 9 years ago

I think I see why Safari is so fast compared to FF/Chromium: it's vAPI.storage.get is synchronous, whereas it is async in FF/Chromium.

chrisaljoudi commented 9 years ago

@gorhill 331 ms with 0.8.8.3.

And yes, I think you're right about it being vAPI.storage.get.

gorhill commented 9 years ago

I am going to try one last thing to improve launch, somewhat trivial: reduce number of async calls at launch, waiting for data.

gorhill commented 9 years ago

Timings to complete start.js (avg of 10 samples), in ms:

Chromium
0.8.8.3
Chromium
0.8.8.5-dev
Chromium
with selfie
Firefox
0.8.8.3
Firefox
0.8.8.5-dev
Firefox
with selfie
810 664 476 878 498 204
-18% -43%

Safari, benchmarked on a different rig:

Safari
0.8.8.3
Safari
0.8.8.5-dev
331 207
-37%

Timings for reloading all default filter lists (avg of 10 samples), in ms:

Chromium
0.8.8.3
Chromium
0.8.8.5-dev
Firefox
0.8.8.3
Firefox
0.8.8.5-dev
485 286 481 311
-41% -35%
AlexVallat commented 9 years ago

Nice! It may only be fractions of a second, but it's the principle of the thing.