mozilla / multi-account-containers

Firefox Multi-Account Containers lets you keep parts of your online life separated into color-coded tabs that preserve your privacy. Cookies are separated by container, allowing you to use the web with multiple identities or accounts simultaneously.
https://addons.mozilla.org/firefox/addon/multi-account-containers/
Mozilla Public License 2.0
2.73k stars 343 forks source link

High energy inpact spikes in about:performance #1691

Closed jarylc closed 3 years ago

jarylc commented 4 years ago

Actual behavior

image

When monitoring about:performance, for some reason the add-on seems to spike to 110-150+ on energy impact and going back down every 2-3 seconds. It persists a browser restart. I've also tried it on Nightly.

I also have an issue where pages seem to have a long 2-3 seconds delay before starting to load, but I'm not sure if it's caused by this.

Expected behavior

Stable energy impact with decent page load speeds.

Steps to reproduce

  1. Launch browser
  2. Visit about:performance and monitor the usage

Notes

Very likely similar to this issue https://github.com/mozilla/multi-account-containers/issues/572

┆Issue is synchronized with this Jira Task

bluevulpine commented 4 years ago

I can confirm I'm seeing similar spikes, and it's causing up to 5 minutes of page load delay for me at times. Restarting firefox can fix it for a while but things slow down again. I'm not sure if the slowdown is time or activity based, but it seems bad if I've left Firefox open overnight.

When I disable this extension, page loads immediately improve.

I don't have this extension on private windows, and those load quickly and normally when normal windows are not.

I have eight containers defined, with a variety of websites opening in each. My work one in particular has ~20 sites defined.

narq commented 4 years ago

I'm also seeing this problem on 75.0 on Mac 10.13.6. I have 20 containers, some with 1 or 2 sites defined, some with around 8 sites defined.

talklittle commented 4 years ago

Next time someone encounters this, try going to https://profiler.firefox.com/ and capturing a profile. I tried on the "Firefox Front-end" capture profile and saw a large amount of CPU time, 75% or so, spent in a JS Async/Await function and a lot of calls related to "Sync", so it must be a regression caused by the new syncing feature in 6.2. Some kind of tight loop attempting to sync too frequently.

Unfortunately I had to drop what I was doing and didn't upload the profile, and haven't reproduced the problem again, so maybe someone else can contribute a profile if they encounter the problem.

bluevulpine commented 4 years ago

Here is a "Firefox Front-end" profile when I was experiencing the performance hit:

https://perfht.ml/3bDNzn8

I started the profile, opened a new default/unassigned container tab, and navigated to Amazon which is set to automatically re-open in a shopping container. Once Amazon loaded I stopped the capture.

I set the capture to include extension information, but if I need to include other options please let me know.

narq commented 4 years ago

I did one too, with an amazon tab set to open in shopping the same as Derek. Not sure I did it correctly, I've never used profiler before.

https://perfht.ml/2W73LXq

talklittle commented 4 years ago

@bluevulpine @narq Thanks for these! The profiles look similar to what I saw on my machine.

To get a clearer picture when viewing the profile results, use the blue "tracks visible" dropdown at the top to show only WebExtensions process, and hit the radio button for "JavaScript" stack (next to All stacks and Native). Excessive CPU time spent in the promise/async/await tight loop, and looks like it's hitting IndexedDB a lot.

narq commented 4 years ago

I've just done 2 traces with the settings you requested - another amazon loading from an empty tab into a shopping tab. And another example from an existing shopping tab, on aliexpress.com, just clicking on a link. When multi-account-containers is running, after a while, everything slows down very dramatically.

https://perfht.ml/2VHmNof - amazon from a an empty tab set to open in shopping container https://perfht.ml/2YcSWGc - clicking a link on aliexpress in pre-existing shopping container

talklittle commented 4 years ago

Anyone have experience debugging WebExtensions? The code is commented decently and even has a mention of infinite loops; in fact this area of code might be the culprit, since the surrounding functions do show up in the profile captures:

https://github.com/mozilla/multi-account-containers/blob/532abbf0324241291fcc533b583aa0d15d32c9dd/src/js/background/sync.js#L111-L128

If we suspect this code, then it could be checkForListenersMaybeAdd() is getting called elsewhere, interleaved with the async execution of this block, and causing the infinite loop. There are only 2 other places it's called; either sync.init(), or there is a caught exception:

https://github.com/mozilla/multi-account-containers/blob/532abbf0324241291fcc533b583aa0d15d32c9dd/src/js/background/sync.js#L201-L213

https://github.com/mozilla/multi-account-containers/blob/532abbf0324241291fcc533b583aa0d15d32c9dd/src/js/background/sync.js#L215-L220

I lack experience debugging WebExtensions though, not sure easiest way to set up an environment that we could trigger a sync and get some debug logs.

kafji commented 4 years ago

I think I have the solution. Could anyone verify if it fixes your problem? https://github.com/mozilla/multi-account-containers/pull/1757

narq commented 4 years ago

Possibly. It's better than it was, and I thought it was fixed for a few days, but #1768 might be part of the same issue, and I'm unable to run it at the moment without my machines getting hammered.

kafji commented 4 years ago

1768 might be part of the same issue

Yeah, I think so too.

Screenshot from 2020-05-30 17-11-05

Hopefully it get fixed soon.

TechNomad615 commented 3 years ago

Has anyone had any luck with a solution for this problem? I have noticed that with the recent updates to Firefox & Nightly this has been getting much worse. I have Windows and Linux systems (multiple distros), so please let me know if there is anything I can do to help resolve this issue.

raghur commented 3 years ago

Can confirm that this is getting worse nightly on linux; One observation is that disabling the addon and enabling it right back again seems to fix it... my CPU idle usage hangs around 1%... when this addon goes wonky, it'll peg one core completely and go to 20%; After disabling/renabling, goes back to 1%

ThomasLobker commented 3 years ago

One observation is that disabling the addon and enabling it right back again seems to fix it

Yes I can confirm. This is also my workaround when it occurs. I go and check about:performance and when Firefox Multi-Account Containers is using 100% CPU I simply disable it for a second. This makes the problem go away for a while.