Closed Bug 1452177 Opened 6 years ago Closed 6 years ago

Youtube memory leak

Categories

(WebExtensions :: General, defect, P3)

59 Branch
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1476032

People

(Reporter: kozlowskib24, Unassigned)

Details

Attachments

(7 files, 1 obsolete file)

Attached image Picture of task manager
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
Build ID: 20180323154952

Steps to reproduce:

All I was doing was watching a YouTube video. The video itself does not matter. Playback was either at 1080p or 1440p 30fps. This occurred yesterday with my laptop using the same version of Firefox watching an entirely different YouTube video. 


Actual results:

By the time I neared the end of the video, I noticed that the video controls were lagging and seemingly unresponsive. Switching over to this tab to type this is showing a distinct delay and unresponsiveness during typing. CPU usage is stuck at about 14% to 20% consistently, seeming that one thread of the 8-thread CPU is stuck at full load. Firefox RAM usage is currently over 3,500 MB and climbing by the second. There are only two tabs open currently, the YouTube video and this bug report. Ublock Origin is the one and only add-on that I use so I suspect that is not an issue. It hasn't crashed yet but I expect it to soon. 


Expected results:

I would normally expect Firefox to reach a few hundred megabytes, maybe up to 1gb of RAM usage during YouTube playback, not over 3GB and one entire CPU thread consumed.
Please enter the address "about:memory?verbose" in the address bar and attach (using the "Attach File" link above) the output here.
Flags: needinfo?(kozlowskib24)
(In reply to Andre Klapper from comment #1)
> Please enter the address "about:memory?verbose" in the address bar and
> attach (using the "Attach File" link above) the output here.

Which button(s) would I press to generate the output that you would want? I haven't submitted one of these before so I am not sure. Either way, I will try to do this the next time I replicate the bug.
Flags: needinfo?(kozlowskib24)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
Build ID: 20180323154952

Hello,

In order to provide the memory report, you need to navigate to the "about:memory?verbose" page, click the "Measure and save..." button and save the file. Afterwards, you can attach the file here. Please do this only when you encounter this issue.

However, I have tested this issue on latest Firefox release 59.0.2, latest Nightly build 61.0a1 (Build ID: 20180411100123) and could not reproduce it. I have accessed a video, https://www.youtube.com/watch?v=rN6nlNC9WQA, set it to 1440p and 2160p and everything worked as expected, without any delays or lag. I've also haven't noticed any increasing CPU usage.
Flags: needinfo?(kozlowskib24)
Component: Untriaged → Audio/Video: Playback
Product: Firefox → Core
To be fair, I should have clarified. This bug does not occur every time I go to watch YouTube. Often it will still work as expected. Therefore, I am not surprised to find that you were unable to replicate it. I will be sure to grab the memory report the next time it happens to me.
Attached file memory-report.json.gz
I have the same problem. Currently the youtube firefox tab is using 2.5GB of memory and it's still rising.
Mike, can you please take a look at the memory report provided in comment 5 and see what might have caused this issue?
Thanks!
Flags: needinfo?(mconley)
Yeah, there's a bunch of memory being used here - the "js-zone" has almost 1GB of stuff going on it, but it's not clear what's holding onto it.

For the folks who are experiencing this, if you disable your add-ons (Help > Restart with add-ons disabled), do you still see the leak?
Flags: needinfo?(mconley)
Attached file memory-report.json.gz
Same problem here. It seems to leak occasionally.

This report was made after closing yt tab (memory usage stopped rising).

- "minimize memory" button didn't work.
- "GC" button did help and there was no further leak after reopening yt.
What would be a normal memory usage for a youtube video at 480p?

I just watched the first 18 minutes of a 57 minutes video and the tab used over 1GB of memory (much less than was used in the memory report above). There is not much happening in the video. Most of the screen doesn't change much. 

When I watch a video with VLC it only uses 180MB of memory. So is the 1GB of memory already too much memory used?
What would be a normal memory usage for a youtube video at 480p?

I just watched the first 18 minutes of a 57 minutes video and the tab used over 1GB of memory (much less than was used in the memory report above). There is not much happening in the video. Most of the screen doesn't change much. 

When I watch a video with VLC it only uses 180MB of memory. So is the 1GB of memory already too much memory used?
Mike, can you please take a look at the memory reports provided in comment 8, comment 9 and comment 12 to see what might have caused this issue?
Thanks.
Flags: needinfo?(mconley)
The memory reports from comment 8 and comment 9 are anonymized, and so I can't really do a deep analysis. It looks as if closing the tab and GC'ing was able to successfully clear the resources, but beyond that... not much there of use.

Comment 12's memory report shows a bunch of JS stuff has been allocated in the Web Content process that has YouTube loaded into it. If I'm understanding the graph correctly, there's a YouTube video loaded within the page of another YouTube video, and the child one is consuming something like ~250MB. The parent one is consuming around ~529MB.

I'm not sure how to interpret the JS stuff that Comment 12's memory report is talking about... hey mccr8, do you have time to check comment 12's report for any actions?
Flags: needinfo?(mconley) → needinfo?(continuation)
The report in comment 8 looks like it could be an issue with compaction. I see "405.51 MB (23.71%) ── unused-gc-things" in there, and they said hitting the GC button helped.

Another interesting thing in that report is this, from one of the content processes:

├──185.56 MB (47.39%) -- dom
│  ├──185.52 MB (47.38%) ── structured-clone-holder [44631]

Somehow we're leaking over 44,000 structured clone holders! Those are also gone in the "after GC" report. The memory usage for that process drops from about 400mb to 76mb. Maybe this means that something (an addon?) is sending lots of data to the main process using message manager, but things aren't getting cleaned up properly?

There's also about 400mb from a detached window in the main process. Maybe there's a leak of a browser window? That also went away.

The memory report from comment 12 also has a fair number of unused-gc-things. There's about 200mb of them, except this time it is in a content process, for a YouTube compartment.

The high memory usage is all JS, in both reports, so I'm going to move it to that component.
Component: Audio/Video: Playback → JavaScript Engine
Flags: needinfo?(continuation)
I'm facing the same issue with random sites: WebMotors.com.br, MercadoLivre.com.br, Zoom.com.br, Google, YouTube, etc. My laptop has a SSD installed, which I think aggravates the issue, because sometimes the memory fills (8GB RAM + 8GB swap) so quickly that neither me or oomkill are being able to react before the system freezes. Sometimes it doesn't freeze, though, and I can confirm from task manager that Firefox is the culprit. This memory leak seems to be triggered only during intense navigation, going back and forth the history of a tab, which I do a lot when researching, so this is really annoying me.

"about:memory" is having trouble saving a useful measurement. Sometimes the saved file is corrupted; sometimes the memory is freed as quickly as it was filled up and the report doesn't capture the high memory usage state -- bear in mind during these spikes the system becomes almost unresponsive to mouse events. By clicking the "Show memory reports > Measure" button instead I was able to capture a high memory usage measurement twice, and both times most of the RAM was spent with "structured-clone-holder", sometimes >6GB, with just 6 tabs, which Firefox normally handles under 1GB.

I searched for "structured-clone-holder" and here I am. I'm using Firefox Developer Edition 62.0b8 (64-bit).

Can you help me capture this report? I can print it to PDF, but I'm not sure this will be useful. Is there some setting that I can change so it automatically triggers the measurement after reaching a high memory watermark?
Attached file ops... uploaded wrong measurement (obsolete) —
Attachment #8992257 - Attachment description: memory-report.json.gz not anonymized with >7GB of structured-clone-holder's → ops... uploaded wrong measurement
Attachment #8992257 - Attachment is obsolete: true
Is browser.storage.local used for YouTube's offline storage?

I'm glancing at bug 1371255, 

> Very bad memory efficiency of browser.storage.local
<jorendorff> sfink: Who's responsible for the heuristics that determine when GC happens?
<jorendorff> sfink: I ask because it seems to be one of these things that falls through the crack between Gecko and SM
<jorendorff> and, full disclosure, I have an old untriaged bug to fob off on someone
<sfink> heh. In the nearish future, I hope to be that person.
<jorendorff> SOLD
<sfink> at the moment, uh... smaug more than anyone else :)
<jorendorff> too late

Steve, if hitting the GC button "helps"... does that mean we could add a dumb heuristic that detects unresponsiveness, and if memory usage is high and a tab was recently closed (or something), force a full GC?
Flags: needinfo?(kozlowskib24) → needinfo?(sphink)
Priority: -- → P3
Whiteboard: [qf]
(In reply to Jason Orendorff [:jorendorff] from comment #21)
...
> and a tab was recently closed (or something), force a full GC?

That is close to what https://searchfox.org/mozilla-central/rev/f2ac80ab7dbde5400a3400d463e07331194dec94/dom/base/nsGlobalWindowOuter.cpp#2190 does
So is this one about the chrome only StructuredCloneHolders... looks like so.
Anyone who is seeing this, which addon's do you have installed?


Looks like our extensions code uses StructuredCloneHolder quite a bit.

Kris, you added the interface. Can you think of cases where such objects are kept alive too long.
Flags: needinfo?(kmaglione+bmo)
(this smells like a WebExtensions bug, not JS Engine)
My bet is ublock since I've got enough reproducible case of YT video playing out of context:

REPRO:

1. goto youtube front page
2. pick random video
3. goto channel of the video owner
4. goto all videos list
5. pick one of the videos and immediately use "go back" button (before video loads)

RESULTS:

- ublock off: nothing happens

- ublock on: after few tries, sound from that video is playing while you are back on the video list. (no memory leak though)
Can someone on the WebExtension team take a look at this to see if this is a reproducible bug.
Component: JavaScript Engine → General
Product: Core → WebExtensions
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Flags: needinfo?(kmaglione+bmo)
Resolution: --- → DUPLICATE
Whiteboard: [qf]
Flags: needinfo?(sphink)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: