Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

[uBlock] Content scripts for cosmetic filtering active despite page being whitelisted #144

Closed
pjlegato opened this issue Mar 27, 2015 · 27 comments

Comments

@pjlegato
Copy link

GMail makes a large number of XHR requests, several per second. uMatrix counts them all, which leads to a very noticeable and annoying delay of several seconds while typing between the moment a key is pressed and when it appears on the screen.

Disabling uMatrix even for the entire site makes no difference, since it continues counting the XHR requests even when disabled.

Please change it to not count requests when it has been disabled for a site, or to have the option of disabling the counts for certain domains or grid squares.

@gorhill
Copy link
Owner

gorhill commented Mar 27, 2015

Sorry but this makes no sense. I think you are assuming how uMatrix work, and drawing conclusions from these (erroneous I suspect) assumptions.

The counter updates lazily, only when network requests have not been seen for a set time.

Something else is slowing down your Gmail, and it can't possibly be uMatrix's counter. Just because the counter updates as you type is no proof of causation.

I just tried to type a mail in Gmail, with uMatrix ans all was fine. There were XHR requests, but not enough to qualify as "large number" in a short time.

So I can't reproduce what you are talking about, I can't make sense of it either given that I know how things work internally. You ask me to change the code and yet you do not show any proof that there is a problem with uMatrix, just an hypothesis based on whatever assumptions you are making about uMatrix.

First, please share your assumptions about how you think uMatrix works.

@pjlegato
Copy link
Author

I do not have any assumptions whatsoever about how I think uMatrix works internally, so there is nothing to share in that regard.

I installed it and it generally works well. GMail is now also operating slowly as described above, which did not happen previously.This seems to have started recently, at approximately the same time I installed uMatrix. I cannot say for sure that uMatrix is the cause, but I also cannot rule it out.

I notice that on most sites, uMatrix shows a count of perhaps 30 or 40 or even 100 connections, and that these counts do not typically change while using the site. I notice that on GMail, unlike all other sites, it shows thousands of connections after a short time, and moreover that the counters continually increase while actively using the site. It is not illogical to hypothesize that these are related.

I will now try disabling uMatrix entirely and using GMail again to see what happens. It could be that some particular interaction between uMatrix and other plugins is the cause. It may also be unrelated to uMatrix.

@gorhill
Copy link
Owner

gorhill commented Mar 27, 2015

One thing I would look at is the dev console of Gmail, and the dev console of whatever extensions you have installed -- including uMatrix, and see if any of them is throwing exceptions non-stop.

@pjlegato
Copy link
Author

I have just conducted a few experiments. Disabling the uMatrix extension and reloading the GMail page causes typing to work normally. Re-enabling uMatrix and reloading GMail causes all typing to be delayed by several seconds before appearing on screen. I repeated the process several times, with the same results. I don't know the exact mechanism at work, but it seems to be caused by some aspect of uMatrix's operation, perhaps only in conjunction with other plugins.

@pjlegato
Copy link
Author

When I activated the dev console, typing began working normally even with uMatrix enabled.

@gorhill
Copy link
Owner

gorhill commented Mar 27, 2015

What are your rules/switches when on Gmail?

@pjlegato
Copy link
Author

As part of my attempts to get typing to work normally, I have uMatrix disabled for all google.com domains. That is why I was surprised to see the counters incrementing frequently. After a page reload, it hits >400 connections quickly, and continues to increase. After an hour or so of light use, it's over 4,000.

@gorhill
Copy link
Owner

gorhill commented Mar 27, 2015

Profiling the page while typing could provide good clues as to what is hogging the CPU. Unfortunately I can't reproduce here, but my Gmail account I only use once in a while to test extensions, I suppose yours is heavily populated.

@pjlegato
Copy link
Author

What is the best way to profile the page? Is there some tool that will show how much CPU each extension uses?

@gorhill
Copy link
Owner

gorhill commented Mar 28, 2015

I usually just launch a profile session from the dev console of the page. The results often look messy but I can easily tell whether the top most contributor is uMatrix/uBlock or not, by looking at the chain of calls. I thnik the profiling data can be saved and I could restore it on my side.

@gorhill
Copy link
Owner

gorhill commented Mar 28, 2015

Just linking these here for reference: gorhill/uBlock#911. It does appear Gmail is often suffering from performance problem.

@pjlegato
Copy link
Author

OK, thanks. I will run a profile the next time I get it to exhibit the slowdown.

@gorhill gorhill closed this as completed Apr 4, 2015
@pjlegato
Copy link
Author

pjlegato commented Apr 6, 2015

I suggest this be re-opened. I ran a profile during a GMail delayed typing event (screenshot below) and found that the bulk of CPU time is spent in mutationObservedHandler at line 478 of contentscript-end.js, which seems to be a part of uMatrix.

Note that this happened on mail.google.com while uMatrix was supposedly disabled for all google.com domains via the power button icon in the UI. This is a bug: the correct behavior for "disabling uMatrix for a domain" is that it should not participate in the page's rendering or operation in any way -- all the observers and other hooks should be removed entirely, not just flagged somehow to not act. CPU time spent in any uMatrix function should be 0 when it's disabled.

It seems anecdotally that this only happens when the badge event count on the uMatrix icon is high (approximately 4k or higher), though this may be a coincidence.

profile

@gorhill gorhill reopened this Apr 6, 2015
@gorhill
Copy link
Owner

gorhill commented Apr 6, 2015

That's not uMatrix, that's uBlock. And by the look of it, version 0.9.2.3, not the latest one.

It does look like it's spending an inordinate amount of time collating the classes. I wish I could step into the code. One thing which could be interesting to find out is the total number of elements with a class attribute on the page when the problem occurs. Typing the following at the dev console should tell:

document.querySelectorAll('[class]').length;

@pjlegato
Copy link
Author

pjlegato commented Apr 6, 2015

I also have uBlock installed, also supposedly disabled for *.google.com. uBlock's UI reports that it is version 0.9.3.0

Typing that into mail.google.com's console, I get:

> document.querySelectorAll('[class]').length;
3613

@gorhill
Copy link
Owner

gorhill commented Apr 6, 2015

3613 is typically high, but I ran benchmark on sites with such high count with no problem, and also, in the context here only the added nodes are queried, not the whole page as document.querySelectorAll does.

When you say "disabled for *.google.com", can you tell me precisely how? Where does *.google.com appear?

@gorhill
Copy link
Owner

gorhill commented Apr 6, 2015

I don't know, I can't make sense much of what I see. It does appear the browser is spending a lot of time in native code land, Element.classList and Element.querySelectorAll.

@pjlegato
Copy link
Author

pjlegato commented Apr 6, 2015

For uBlock: I loaded mail.google.com, then clicked the uBlock icon, then its big "power button" icon, so that it and the uBlock icon both turned grey. The status line now reads "0 or 0%".

For uMatrix: I loaded mail.google.com, then clicked the "power button" icon to disable it. When this didn't fix the problem, I clicked the "mail.google.com" box and changed it to "google.com," in the hopes that the more expansive scope would fix it.

@gorhill
Copy link
Owner

gorhill commented Apr 6, 2015

then clicked the uBlock icon, then its big "power button" icon, so that it and the uBlock icon both turned grey

Did you reload the page afterward? If the page is whitelisted, uBlock is not supposed to run the code I see in your screenshot.

@pjlegato
Copy link
Author

pjlegato commented Apr 6, 2015

Yes, I've reloaded the page many times. I turned uBlock and uMatrix off for GMail months ago. I've also restarted the browser and rebooted my computer many times since then.

@gorhill
Copy link
Owner

gorhill commented Apr 6, 2015

Testing on my unused Gmail account (it's full of emails as I used the email address on various sites just to get stuff), I get 7068 elements with a class attribute, and profiling while I type in a new mail, uBlock does not show in the profiling results, I can't find it, meaning its most expensive call is below 1 ms.

What other extensions you have installed, if any?

@gorhill
Copy link
Owner

gorhill commented Apr 6, 2015

How much memory do you have? Any possibility that your computer was swapping memory because of low memory condition?

@pjlegato
Copy link
Author

pjlegato commented Apr 6, 2015

I have 8 gigs of RAM and was not doing anything particularly memory intensive at the time (as far as I know.) Do uBlock / uMatrix themselves consume a lot of memory? The next time I can reproduce the condition again, I'll check for swapping explicitly.

@gorhill
Copy link
Owner

gorhill commented Apr 6, 2015

Do uBlock / uMatrix themselves consume a lot of memory?

Depends, as said in another issue: #147.

This user too had 8 GB. The thing is, Chromium does indeed consume a lot of memory, and often it takes a while to be garbage collected -- you kind of have to force it as seen in the benchmark in the above issue. Chrome is certainly even more memory hungrier than Chromium because it has internal extensions which Chromium does not have by default.

In the above issue, the hidden iframes were not helping at all, so another thing to check is the number of iframe on the page, though we are talking about recursivity here, it could be a frame itself which is full of iframes, and this can't be easily seen from the console. The fact that you have a high request count is a hint that there could be some DOM craziness going on (non-stop creation/embedding of iframes -- everything is possible).

@pjlegato
Copy link
Author

pjlegato commented Apr 6, 2015

The other issue is that uBlock and/or uMatrix are apparently still doing something even though I have disabled them both for GMail. Is this a legitimate bug?

@gorhill
Copy link
Owner

gorhill commented Apr 6, 2015

The other issue is that uBlock and/or uMatrix are apparently still doing something even though I have disabled them both for GMail. Is this a legitimate bug?

Yes, I want to look into this.

@gorhill
Copy link
Owner

gorhill commented Apr 7, 2015

I confirm that the content script taking care of cosmetic filtering can end up lingering in the page even when a site is whitelisted. It's because all is asynchronous, so sometimes the information needed by a content script that it should abort is not available at the time it is checked. Solution is to check every time the content script receives an answer from the background page.

Fix will be in next release (also in next dev release)

gorhill added a commit to gorhill/uBlock that referenced this issue Apr 8, 2015
@gorhill gorhill changed the title Don't count requests when disabled, to avoid noticeable slowdown [uBlock] Content scripts for cosmetic filtering active despite page being whitelisted Apr 8, 2015
gorhill added a commit to gorhill/uBlock that referenced this issue Apr 10, 2015
gorhill added a commit that referenced this issue Apr 10, 2015
Noxgrim pushed a commit to Noxgrim/uMatrix that referenced this issue Dec 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants