Closed Bug 1501238 Opened 6 years ago Closed 5 years ago

Twitch.tv live stream wasm web worker has high memory fluctuations

Categories

(Core :: JavaScript: GC, defect, P3)

65 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla70
Tracking Status
firefox65 --- affected

People

(Reporter: ke5trel, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: memory-footprint, Whiteboard: [MemShrink:P2])

Attachments

(3 files)

Attached image mem-graph.png
Viewing a live Twitch stream can see memory fluctuate significantly, averaging 750MB and exceeding 1GB at the peaks while Chromium remains relatively stable at 350MB (see graph). Testing was done on Ubuntu 18.10 with each browser displaying the same Twitch stream simultaneously.

about:memory seems to indicate this is due to a wasm web worker with most allocations in class(ArrayBuffer) malloc-heap.

https://cvp.twitch.tv/2.6.29/wasmworker.min.js
Attached file memory-report.json.gz
From the picture, this smells like memory growth followed by some kind of GC or (more likely) malloc coalescing, though I've not looked at the memory report yet.
Are the ArrayBuffers the normal kind (with the fluctuations under malloc-heap/elements -- normal) or the special wasm/asm.js kind (with the fluctuations under non-heap/elements/wasm or malloc-heap/elements -- asm.js)?

If it's the former, than I would expect the difference we're seeing here relates to worker GC scheduling and is not directly tied to wasm.
The fluctuating ArrayBuffers are the normal kind (malloc-heap/elements/normal).
Ok, since, last I heard, worker GC scheduling is a known issue with possible plans to work on, I'll tentatively kick this over to the GC component.
Component: Javascript: Web Assembly → JavaScript: GC
Whiteboard: [MemShrink] → [MemShrink:P2]
The memory gradually ramping up over 5 minutes then dropping is weird. I wonder what sort of limit we're hitting. This sounds like either an issue with mallocbytes not being updated, so the GC doesn't realize it needs to run, or maybe the memory was GCed, but some communication back to the main thread that is needed to finally release things is being delayed. I guess the latter doesn't sound too likely given how long and how regular the spike then drop is.
Blocks: GCScheduling
Priority: -- → P3

This is probably due to the way we track malloc memory associated with GC things. We don't have size information when we free malloc memory so we just track total allocation size since the last GC. If this hits a threshold we trigger a GC and increase the threshold. I suspect that GC is freeing the memory, but because we keep hitting this threshold we keep increasing it, so GCs become increasingly rare. Ideally we'd have retained size information which we would use to set the threshold appropriately.

Blocks: 1533449
No longer blocks: GCScheduling

Firefox 66 still allocates 1 GiB of memory for 1 Twitch.tv tab.
I think this bug affects other video sites too.

This doesn't seem to happen in nightly any more, but it didn't always reproduce for me. Can you check whether this is still a problem?

Flags: needinfo?(ke5trel)
Attached image mem-graph-after-fix.png
Flags: needinfo?(ke5trel)
Status: NEW → RESOLVED
Closed: 5 years ago
Depends on: 1569560
Resolution: --- → FIXED
Target Milestone: --- → mozilla70

(In reply to Kestrel from comment #11)
\o/

Thanks for confirming.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: