-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
High CPU usage for tab loading animation #1384
Comments
Thank you for porting Tree Style Tabs to a WebExtension! I had not realized how much I missed it until installing it again :) Thank you as well for including the "Extra style rules for sidebar contents" config, it’s a nice escape hatch for small hacks. I’ve used it to temporarily replace the throbber animation with something much cheaper (if uglier): .tab.loading:not(.collapsed) .throbber::before,
:root.blocking-throbber #blocking-screen .throbber::before {
animation: throbber 1s frames(2) infinite;
}
.throbber::before {
box-shadow: none;
border-radius: 0;
border-width: 3px
}
@keyframes throbber {
from { transform: translateX(-6px) }
} |
There are two points:
After I read your descriptions, I thought that migration to transform seems the most important. Is it correct? |
I experimentally rewrite the animation with CSS transforms. For more natural animation it should be improved more, but It actually reduces CPU usage for me. How about this? @keyframes throbber {
0% { transform: translateX(0); }
3% { transform: translateX(0); }
20% { transform: translateX(calc((var(--favicon-size) - var(--throbber-size)) / 2)) scaleX(2); }
47% { transform: translateX(calc(var(--favicon-size) - var(--throbber-size))); }
53% { transform: translateX(calc(var(--favicon-size) - var(--throbber-size))); }
70% { transform: translateX(calc((var(--favicon-size) - var(--throbber-size)) / 2)) scaleX(2); }
97% { transform: translateX(0); }
100% { transform: translateX(0); }
}
.throbber::before {
left: 0;
}
.tab.loading:not(.collapsed) .throbber::before,
:root.blocking-throbber #blocking-screen .throbber::before {
animation: throbber 1.05s steps(60) infinite;
} |
It still uses CPU 10% or more for me. Hmm... |
FYI this is how I animate the throbber. |
Finally I've replace the implementation totally. d56d1e6 |
Your implementing throbber with |
I forgot to set |
@asamuzaK Thank you for advises! Updated version based on your code: @keyframes throbber {
0% { transform: translateX(0) scale(1, 1); }
17.5% { transform: translateX(calc((var(--favicon-size) - var(--throbber-size)) * 0.625)) scale(1.6, 0.9); }
50% { transform: translateX(calc(var(--favicon-size) - var(--throbber-size))) scale(1,1); }
67.5% { transform: translateX(calc((var(--favicon-size) - var(--throbber-size)) * 0.625)) scale(1.6, 0.9); }
100% { transform: translateX(0) scale(1, 1); }
}
.throbber::before {
left: 0;
}
.tab.loading:not(.collapsed) .throbber::before,
:root.blocking-throbber #blocking-screen .throbber::before {
animation: throbber 1.05s ease infinite;
} |
The throbber is still using significant CPU on 2.0.1, at least for me. I suppose that using |
Hmm, are there any noticeable differences in these three examples? |
I'm using 2.0.7 and the loading symbol makes 90% CPU usage on my laptop. Which of the above code snippets are still up-to-date that you'd recommend to mitigate this locally in the short term, no matter how ugly? |
Because, oddly even the solution from above (#1384 (comment)) that just makes a square hop left and right wit 2 FPS, causes my Firefox to go > 50% CPU when connecting to http://localhost:1234 after running This is assuming it is actually the animation that causes it and not something else about loading pages that hang in Firefox. |
OK, turns out that this problem even exists with
Not sure if this is a TST or Firefox problem. |
OK, so with TST disabled, the CPU usage goes down to 30%, still horrible for doing nothing.
I wonder if what I'm observing is the CPU time taken by Firefox's actual loading animation even though I have hidden the top tab bar. |
I experimented with Firefox's tab throbber animation a couple of weeks ago and from what I can remember it causes high CPU usage if it is hidden in any way. For example, it will causes high CPU usage if a throbber is placed outside of the visible area, if a throbber's opacity is set to 0 or if a throbber is set to Don't know if this happens anywhere in the extension but thought I should mention it anyways. |
Here's some more data, with a Thinkpad X220 which can report accurate power consumption information via the
So the throbber doubles my laptop's power consumption, despite nothing being loaded. (Using the blocky-jumpy throbber instead of the smooth one redures the problem only insignificantly, by ~1W.) |
I can confirm what @Lej77 said. When NOT hiding the normal FF tab bar, then having a normal throbber in TST and the FF tab bar has this Wattage impact:
When hiding it with
The alternating ~12W/24W are consistent with the alternating 20%/100% CPU usage shown in htop. When the native FF tab bar is shown, then the CPU usage does not go over 15%. Summary:
|
@nh2 What about when hiding FF tab bar and not using the TST sidebar? |
Summary:
Edit: It also makes no difference if TST is entirely disabled or just the TST bar hidden with F1. (As a reminder, to make a page that can't load I use |
@nh2 So this is a bug in Firefox then? Its not an actual problem with TST itself? |
@nh2 Also i wrote some more about hiding throbbers without performance issues on Issue 1543. Don't know if that can be used to hide FF tab throbbers without performance issues though. |
I edited to add a bit more info:
I think there is at least a bug in Firefox, as even if TST is not installed, CPU usage goes up when the native tab bar is hidden. For the HORRID entry in the table, it is unclear to me whether this is a bug in Firefox or in TST. |
@nh2 How big is the difference between "good", "slightly worse" and "HORRID"? |
@Lej77 that's the numbers I reported above; in table form:
|
@nh2 I can't reproduce your high CPU usage for just one infinite loading tab. I get around 3-4% CPU with the sidebar open and 2-3% CPU with it closed. I am using TST v2.2.11 on Firefox 57 on Windows 10. Also firefox tab bar is hidden. |
@Lej77 I'm on Ubuntu 16.04, Firefox Nightly 59, TST v2.2.11. |
@nh2 Using Windows 10 I have tested with Firefox 57 and Firefox Nightly 59. Both with and without hidden firefox tab bar. I do notice lower CPU usage for both 57 and 59 without hiding firefox tab bar but its only about 1% difference and the total CPU usage is about 2-6%. |
@nh2 Also I noticed another bug when I was investigating this one. I wrote about it on a comment for Issue 1535. Don't know if you are affected but if you are then you might want to be careful not to trigger it. It should only be an issue if you have many tabs though. |
By the way, https://httpbin.org/ also has https://httpbin.org/delay/60 (where 60 is a number of seconds). |
Depending on the state you're trying to get the browser into, you might also find the testcase I wrote for Bug 1276100 useful. It's the only attachment and it's a Python script which holds an HTTP response incomplete at just the right stage to wedge the browser into a confusing in-between state. (Basically, Firefox malfunctions if the server leaves the response in a "document begun streaming but not enough received for an initial paint" state for long enough for the user to poke at it. There are details in the bug and the script itself will also present instructions when launched.) |
i have created https://bugzilla.mozilla.org/show_bug.cgi?id=1419096 to report this problem upstream, especially the fact that CPU usage increases if the throbber is hidden. |
also, by disabling firefox's own throbber in |
@bitonic Mind sharing how you disabled both in userChrome.css to hold us over for now? |
ah yes, apologies:
|
Can you please gather a performance profile? You can use the tool at https://perf-html.io/ to find which parts of the code are taking the most time. |
maybe this is related to tab cycling slowdowns when using extension hotkeys? switching between tabs with vim-vixen shift+j/k there is some serious lag compared to the master hotkeys ctrl+pgup/pgdown. |
I'm seeing the same problems with TST (and horizontal tab bar and top-of-TST bar successfully hidden via userChrome.css) on Linux Mint 18.3. @bitonic's CSS to hide the throbber isn't working for me... Still seeing the throbber everywhere, and massive CPU hits (with 60ish tabs open in 2 windows), including lots of blocking freezes (fairly frequently forcing a full kill -9 of Firefox from a console), especially on JS-intensive pages (e.g. tweetdeck). |
Hello @piroor! From throbber.css; If the animating element is scrolled out, the animation consumes more CPU than the situation where the animation is visible. I've been trying to fix it in bug 1419079, but if you could specify 0% value there (actually the value should not be transform:none, since we can't optimize the transform:none case), this high CPU usage will be solved. Thanks! |
@piroor Thanks for the quick fix! Yeah, that's exactly what I've expected. |
@hiikezoe Now the animation target is intentionally placed out of screen and referrenced as a mask image via |
@piroor Interesting. Bug 1190721 just tries to stop calculating animation styles on out-of-view elements. I am not sure such animations referenced via -moz-element work fine. Would you mind uploading a simple test case somewhere? I'd like to see what happens there. |
@hiikezoe I've created a simple testcase. It seems to work as expected on my environment: Nightly 59.0a1 (Build ID 20171127220446) on Ubuntu 16.04LTS. |
@piroor Thanks for the test case! The test case noticed me that there are two issues we need to tackle.
The throbber animation in the test case works fine due to 1) for now. Anyway bug 1190721 does not affect the test case at all, and I am going to do optimizations for animations with the test case in my mind. I am not sure using a single animation and referencing the animating element from multiple elements is better for CPU usage rather than specifying an animation on each element respectively though. |
Does this off-screen throbber still exist when there are no visible throbber? Could https://bugzilla.mozilla.org/show_bug.cgi?id=1417460 be related to this? |
@SimonSapin The throbber element exists always. But animation is applied only when there is one or more loading tab. :root.have-loading-tab #master-throbber,
:root.blocking-throbber #master-throbber {
animation: throbber 1.05s steps(60) infinite;
} The class |
hiikezoe mentioned "To be precise, bug 1190721 is also necessary to reduce the CPU usage, so we still need to wait for firefox 58." I'm on: Not sure when the relevant commit is supposed to be released, but for me disabling the throbber still results in considerably less CPU during page loads. (I used the following code to disable the throbber, but it might be imperfect or overkill - I'm far from a CSS expert.) |
@Omen-of-Peace I guess you might need to set display:none for #master-throbber element. It's the only one animating element for all throbbers in TST, IIUC. |
I close this because outdated. |
Short description
The
@keyframes throbber
animation is expensive. "Normal" tabs in Firefox 57 / 58 have a similar-looking animation but it’s implemented in a completely different way:border-radius: 100%
, and animates thewidth
andleft
properties.chrome://browser/skin/tabbrowser/loading.svg
) as a background-image in a pseudo-element that animatestransform: translateX(…)
with asteps(60)
timing function.As far as I understand, the latter is cheaper in current Firefox because things with animated
transform
are often painted into a separate layer that can be preserved and re-composited without re-painting when the transform changes. In comparison, changing the width of something withborder-radius
requires re-painting it.Steps to reproduce
netcat -l 8888
or some other command to start a TCP server that will accept an HTTP request but never send a responseExpected result
This animation by itself should not use a significant amount of resources.
Actual result
Firefox uses 40% ~ 80% CPU even though it is doing nothing else. This makes loading actual pages slower.
Environment
The text was updated successfully, but these errors were encountered: