Closed Bug 1810876 Opened 2 years ago Closed 2 years ago

opacity:0 element with CSS compositor runnable animation still consumes CPU

Categories

(Core :: CSS Transitions and Animations, defect)

Firefox 109
defect

Tracking

()

RESOLVED FIXED
111 Branch
Tracking Status
firefox111 --- fixed

People

(Reporter: stefan-bmo, Assigned: emilio)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

Attachments

(2 files)

Attached file animates-opacity-0.html (deleted) —

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0

Steps to reproduce:

  1. Open attachment as reproducer
  2. Open a CPU monitor (htop or otherwise)

Actual results:

Observe that Firefox uses a lot of CPU to draw an empty page.

I'm assuming this requires that rendering/compositing is done on the CPU and not the GPU. FWIW, I have uploaded a power profile: https://profiler.firefox.com/public/zv8g0qqdjf9vv798ghtdyvvczzn74mtgv9yrxc8/calltree/?globalTrackOrder=0&thread=0&v=8

Expected results:

Firefox uses almost no CPU.

This is the case for hiding the element using "visiblity:hidden" or "display:none". However, the example uses "opacity:0" where seemingly no optimization is applied.

Potentially related bugs:
https://bugzilla.mozilla.org/show_bug.cgi?id=1166500
https://bugzilla.mozilla.org/show_bug.cgi?id=1218169

The Bugbug bot thinks this bug should belong to the 'Core::Graphics: WebRender' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Graphics: WebRender
Product: Firefox → Core

Testing with gfx.webrender.all=true, the CPU usage increase is still present compared to "display:none" and other more optimized paths. Eyeballing it on my machine is <1% CPU usage if no animation or optimized code path, ~9% with webrender and opacity:0, and ~60% with webrender (software) and opacity:0.

Here's a profile on my machine: https://share.firefox.dev/3QPUUVW

This is almost a duplicate of bug 1761752, but the behavior is worse here, as we actually composite. Maybe because the CSS animation animates the transform property that can be animated on the compositor, whereas the testcase in bug 1761752 animated the background-position property.

Blocks: power-usage
Status: UNCONFIRMED → NEW
Component: Graphics: WebRender → CSS Transitions and Animations
Ever confirmed: true

If you set opacity: 0 on the container then behavior should be much better. We're hitting this case almost surely. I wonder if this call can be changed to CanOptimizeAwayDueToOpacity, which would catch this... I don't see anything in bug 1427033 which indicates that it's not possible.

Flags: needinfo?(emilio)
Flags: needinfo?(emilio)
Assignee: nobody → emilio
Status: NEW → ASSIGNED

Florian is right. This is a special case that transform and transform-like properties are able to run on the compositor thread. And thank you Emilio!

Summary: opacity:0 element with CSS animation still consumes CPU → opacity:0 element with CSS compositor runnable animation still consumes CPU
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/384f12d8ad22 Throttle animations in opacity: 0 root. r=hiro
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 111 Branch

Is it expected that we still paint every 200ms? https://share.firefox.dev/3D0DUH4

Flags: needinfo?(emilio)

That's the time that we throttle the animations that affect the overflow area on the main thread here, so yes.

Flags: needinfo?(emilio)
Depends on: 1811463
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: