Throttle status bar spinner animations to save CPU#96096
Merged
joaomoreno merged 1 commit intomicrosoft:masterfrom Apr 27, 2020
Merged
Throttle status bar spinner animations to save CPU#96096joaomoreno merged 1 commit intomicrosoft:masterfrom
joaomoreno merged 1 commit intomicrosoft:masterfrom
Conversation
kassens
reviewed
Apr 24, 2020
| .codicon-animation-spin { | ||
| animation: codicon-spin 1.5s linear infinite; | ||
| /* Use steps to throttle FPS to reduce CPU usage */ | ||
| animation: codicon-spin 1.5s steps(30) infinite; |
There was a problem hiding this comment.
Note this is 30 steps per 1.5s, so 20fps (there might be an off by 1 error in my calculation, not sure how steps work on repeat).
Contributor
Author
There was a problem hiding this comment.
Good point, thanks. I still think it's a good level of visual smoothness for the performance win here, even if that means it's 20FPS instead of 30FPS.
Member
|
Very interesting approach, I like it! Thanks! 🍻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes (well, improves) #96094, where spinners in the status bar cause higher-than-desired CPU usage in the "Code - Helper (GPU)" process. It's just showing a spinner, which should require very little CPU usage. If the animation is throttled to 20FPS, the CPU usage drops by a lot while still appearing visually smooth. In my typical usage with extensions and files open, my CPU usage in the GPU process goes from ~25% to ~10%. When repro'd on a blank build of OSS VS Code, this is less dramatic (5-8% to 2-3%) but still quite nice. This helps reduce battery drain, especially if you have a lot of extensions that show spinners. Note of course that the measurements here are specific to my machine and are kind of eye-balled.
The spinner still appears quite smooth after this:

(Keep in mind this gif is capped at 25FPS, but it is still somewhat representative of how it looks)
I think it could go down to <20FPS and still look OK, with commensurate decreases in CPU usage (down to 5-8% instead of 10%).
Another option would be a "low power mode" setting for this, and allow this to go down to more like 15-18FPS for much bigger reductions in CPU. This PR just does the minimal change that maintains smoothness to be non-contentious.
How to test this change:
Add an extension which creates a status bar spinner, e.g.:
When this is visible, look at activity monitor / some other process list. Notice CPU% usage of "Code - OSS Helper (GPU)". If you use devtools to reset the
stepsCSS change tolinear, notice an increase in the activity monitor %CPU (or check before and after this PR for the same workspace).