Bug 256123 - [GStreamer] Constant CPU usage on autoplaying videos, even when out of viewport
Summary: [GStreamer] Constant CPU usage on autoplaying videos, even when out of viewport
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Normal
Assignee: Philippe Normand
Keywords: Performance
Depends on:
Blocks: GLibPerformance
  Show dependency treegraph
Reported: 2023-04-28 21:32 PDT by Jeff Fortin
Modified: 2023-05-12 08:30 PDT (History)
2 users (show)

See Also:

sysprof capture (1.11 MB, application/x-xz)
2023-04-28 21:38 PDT, Jeff Fortin
no flags Details
sysprof screenshot (221.33 KB, image/png)
2023-04-28 21:39 PDT, Jeff Fortin
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Fortin 2023-04-28 21:32:32 PDT
Test case: https://interbrand.com and its autoplaying video, since Epiphany 44.2 defaults to allowing muted autoplaying video.

1. Load that page. See the video playing.
2. Pause video playback using their pause button next to the unmute button.

Result: with WebKitGTK 2.40.1 and GStreamer 1.22.2, even on a modern 8-logical-CPUs 8th-generation Intel Kabylake CPU+GPU running on Wayland with triplebuffering, even with playback paused, CPU usage continues at 35 to 50% of all cores, and the cores stay clocked around 2.4-2.5 GHz instead of going back down to 800 Mhz.
Comment 1 Jeff Fortin 2023-04-28 21:38:57 PDT
Created attachment 466135 [details]
sysprof capture
Comment 2 Jeff Fortin 2023-04-28 21:39:22 PDT
Created attachment 466136 [details]
sysprof screenshot
Comment 3 Jeff Fortin 2023-04-28 21:42:03 PDT
I forgot to mention: this is vanilla Epiphany 44.2 from Fedora 38, without doing anything to make it use VA-API HW video decoding acceleration, so it's probably doing everything on the CPU... but I don't see why it would keep doing that once the video playback is stopped.
Comment 4 Jeff Fortin 2023-04-29 06:30:58 PDT
...and to be clear, the video I am talking about in this page is the 1st video at the very top, that is as part of the banner's background, and is autoplaying on loop silently on load;

I was not referring to the 2nd video in the middle of the height of the page (that you have scroll to and click to play), though maybe that one would also exhibit the issue, I don't know.
Comment 5 Philippe Normand 2023-04-29 07:14:57 PDT
This page loads not one, but 4 videos:

- the one you reported the issue about, the interview. MSE, from Vimeo
- 3 videos stored on a old-fashioned HTTP server, playing in loop:
  * https://interbrand.com/wp-content/uploads/2022/10/data-animation_apple_v04.mp4 
  * https://interbrand.com/wp-content/uploads/2022/10/GE.mp4.mp4 
  * https://interbrand.com/wp-content/uploads/2022/10/crop-piezas-2.mp4

So even if you pause the first one, the 3 others keep playing... That's what using your CPU, most likely. And unlikely I doubt we can do anything about it...
Comment 6 Jeff Fortin 2023-04-29 07:28:26 PDT
Interesting! Could their playback be automatically stopped when they are not in the currently visible view, however? There's probably no reason to play them off-screen if they're not WebRTC, especially if they are muted or silent?
Comment 7 Philippe Normand 2023-04-29 10:39:26 PDT
Maybe yes.
Comment 8 Philippe Normand 2023-04-29 10:43:11 PDT
Likely related, MediaPlayerPrivate methods we should(?) override:

    virtual void setPageIsVisible(bool) = 0;
    virtual void setVisibleForCanvas(bool visible) { setPageIsVisible(visible); }
    virtual void setVisibleInViewport(bool) { }
Comment 9 Philippe Normand 2023-04-30 03:52:00 PDT
(In reply to Jeff Fortin from comment #6)
> Interesting! Could their playback be automatically stopped when they are not
> in the currently visible view, however? 

It's technically possible but UX-wise, huh, terrible?
Imagine loading some YT video, start playing it and then scroll down to read the comments, the video would pause... your CPU would be happier, but would you? I'm not sure that'd be a great idea?
Comment 10 Jeff Fortin 2023-04-30 05:44:29 PDT
I'm talking about silent or muted videos here, those should never be playing offscreen (or when the tab is unfocused, or when the window/app is unfocused). Playing videos that have sound, of course, would be expected to keep playing until stopped by the user (or the video reaches the end).
Comment 11 Philippe Normand 2023-04-30 11:55:28 PDT
I've got a WIP patch, needs a bit more testing.
Comment 12 Philippe Normand 2023-05-07 03:25:56 PDT
Pull request: https://github.com/WebKit/WebKit/pull/13549
Comment 13 EWS 2023-05-12 08:30:36 PDT
Committed 264017@main (0218f0f88a9c): <https://commits.webkit.org/264017@main>

Reviewed commits have been landed. Closing PR #13549 and removing active labels.