Tabs use "excessive" CPU when application is backgrounded #28452
Comments
(Edited to delete comment about Focus (
I think ActivityMonitor sees Fenix in the background using more than 2% of the CPU time during a given time window, and it kills it... I think the times are in milliseconds so the window is quite large, minutes In the first example below, at 08:47:03 fenix tab24 uses 9100 ms of CPU in an interval of 300362 ms and (9100*100/300362) = 3.02%, against a target limit of 2%, and it gets killed. Etc Examples Both tab processes in Nightly being killed simultaneously:-
Beta's main process being killed even though Beta is "stock", it has no Sync and no Add-ons installed:-
|
(edited title to reflect new understanding) With Fenix, if a tab is loaded but not viewed that tab uses CPU indefinitely until the tab is viewed. Even if Fenix is put into the background, that tab still uses some CPU. The amount of CPU seems to depend on number of loaded-but-not-viewed pages; whether that page is in a new or existing tab; and the exact page content. But it can be substantial >10% CPU use per tab. You don’t really need detailed STR but I have given them below. Just open several tabs in the background by long pressing a link and selecting "open link in new tab". Do not view the new tabs. Watch about:processes or use Example high background CPU pages:- www.telegraph.co.uk; edition.cnn.com. Not all are as bad as this, I will post more if I find them. The constant use of CPU resources in the background can cause I think Focus suffers more from this problem than Fenix but I am not clear about the details. As soon as Focus has any tab loaded, OneUI 5 shows a “1 active in background” warning in the task switcher which I don’t see for any other app. Tapping the warning says “Check background activity. These apps and services are active while running in the background: Firefox Focus" Presumably this also wastes battery. Steps to reproduce Here I use eight background tabs to exaggerate the effect but I think even two or three is enough to cause problems. It could be vendor/CPU/Android version dependent (I have Galaxy M32, Android 13, OneUI 5). In the comments above it seems
To trick (this is fairly repeatable but doesn't always work) repeat steps 1 through 10. Fenix has eight unviewed background tabs, and the Fenix app is in the background. Leave phone untouched for 30 minutes. I think Focus is affected even worse but I have not looked in detail. Fenix in foreground with 8x unviewed background tabs:- https://share.firefox.dev/3kgBQEp Fenix in background with same 8 unviewed background tabs (waited 30 seconds after backgrounding):- |
High CPU load sites:- walgreens.com; bestbuy.com; ibm.com/design; xbox.com; google.com Turning off Javascript in about:config helps somewhat. I think script-heavy sites that are loaded but not viewed can keep "doing stuff" indefinitely until they are viewed, even if Fenix is in the background. |
Thank you for this investigation, @Cheap-Skate. I will move this ticket to Bugzilla where we track all work related tab kills / reloads. Thanks also for attaching the profiles! |
Moved to bugzilla: https://bugzilla.mozilla.org/show_bug.cgi?id=1810550 Change performed by the Move to Bugzilla add-on. |
Steps to reproduce
STR: Open Firefox Beta and/or Nightly. Open 3-4 tabs. Leave for a few hours. Firefox gets killed by ActivityManager due to "excessive CPU". Hav
I'd like to re-open #23140, I see this issue quite a lot on Nightly and on Beta, several times per day, usually when the phone is locked and in my pocket. I have tried:- logging out of Firefox sync; making the app "unrestricted" in battery monitor; comparing Beta with Nightly. Nothing really makes much difference. Sometimes a tab process gets killed and I lose half my open tabs, sometimes the main process gets killed and Firefox cold launches when I switch to it.
I had Beta and Nightly opened simultaneously on my phone, each with 3-4 tabs open. They were both killed at different times this morning, typically when the phone was at a low level of activity as seen in the logs below
Expected behaviour
Firefox should not get killed due to excessive CPU
Actual behaviour
Several times per day Firefox parent or one tab process gets killed, resulting in loss of half my open tabs or complete closing of the app and re-launching
Device name
Galaxy M32
Android version
Android 13
Firefox release type
Firefox Beta
Firefox version
109.0b5
Device logs
Investigating the Beta kill in more detail, there is nothing exciting in the log beforehand, the phone was at a very low level of activity:-
Additional information
No response
┆Issue is synchronized with this Jira Task
The text was updated successfully, but these errors were encountered: