model-viewer icon indicating copy to clipboard operation
model-viewer copied to clipboard

Memory Leaks and GPU Crashes in recent model-viewer versions

Open hybridherbst opened this issue 6 years ago • 8 comments

Description

I noticed that there seems to be new issues in terms of memory handling in model-viewer (or in Chrome, I don't know). I'm not 100% sure but I think this is a regression.

When working on models and doing frequent refreshs (e.g. through Glitch), memory leaks and ultimately leads to browser crash / system freeze. The same seems to happen for graphics memory, I've seen black screens, GPU crashes recently. This is not only on Chrome Windows, but also on Chrome Android (I've had cases of black screens and fully glitched out system-wide GPU issues which I've never seen on Android, needing a full phone restart to resolve).

Might be related to #1074

Live Demo

I've seen this when working on regular 1-model pages, but it reproduces faster with this stress test here: https://glitch.com/edit/#!/model-viewer-stresstest (these are duplicate model files, not the same one loading multiple times).

  1. open glitch page
  2. open "In A New Window"
  3. open the glitch editor and the new window next to each other (so that both are visible)
  4. open Task Manager to watch RAM
  5. insert space anywhere in glitch, let page refresh
  6. wait for loading done
  7. repeat repeat repeat
  8. watch RAM all the time

20200326-121605

The same seems to be true when just refreshing the page, but I had the feeling it's faster when glitch causes the update (not sure). Also, I had the feeling that the speed of leaking is increased when the page is in "mobile preview" mode (not sure). image

Browser Affected

  • [X] Chrome
  • [ ] Edge
  • [ ] Firefox
  • [ ] Helios
  • [ ] IE
  • [ ] Safari

OS

  • [X] Android
  • [X] iOS
  • [ ] Linux
  • [ ] MacOS
  • [X] Windows

Versions

  • model-viewer: >= v0.9.0 (not sure if a regression or I just now noticed it)

Edit: Checked "iOS" as well as I'm getting the same black-model issues on iOS with the same "strategy" of many refreshes after each other. Sometimes after page refresh, sometimes after coming back from QuickLook.

hybridherbst avatar Mar 26 '20 11:03 hybridherbst

I also noticed that GPU usage, on a high-end machine, now goes to nearly 100%. Have you maybe removed the frames-per-second clamping? Usually you want to clamp to device framerate, and if not possible, to 60.

hybridherbst avatar Mar 27 '20 22:03 hybridherbst

@soraryu thanks for reporting. I have to do some testing on my own, but some initial thoughts:

  • To some extent, memory leaks may be outside of our control, but we can certainly report them upstream to Chrome. It would be interesting to see if these leaks also happen in other browsers.
  • We have had some reports of long-lived <model-viewer> elements acting badly e.g., #1074

cdata avatar Apr 02 '20 17:04 cdata

For some initial anecdata, I tried out the stress case in Chrome on my 15" MacBook Pro.

image

Although overall CPU usage was high, the stress test tab was only at about ~75". This is honestly around what I would expect for what amounts to a very relatively hard scenario for <model-viewer>:

image

image

cdata avatar Apr 02 '20 17:04 cdata

Have you maybe removed the frames-per-second clamping? Usually you want to clamp to device framerate, and if not possible, to 60.

@soraryu on this topic, IIRC we do not rate limit FPS at this time (we just use whatever requestAnimationFrame gives us). This means we'll likely be rendering at 90, 120, 144 FPS etc. depending on your display refresh rate. We haven't done much investigation to determine how problematic this is. Can you confirm your display frequency for us?

cdata avatar Apr 02 '20 17:04 cdata

I wasn't even aware of it but turns out my laptop has a 240 Hz display. That being said, there's a 2070 Max-Q in there, and I'm developing graphics-heavy apps day in and out with millions of polygons and dozens of fx passes, and the GPU doesn't get as heavy a hit as with model-viewer. I can't remember that being the case with past versions though, but might be mistaken. I definitely didn't have as many (or actually, zero) crashes when I started working with model-viewer.

Also, screen framerate does seem to have some but not much influence on GPU utilisation:

At 240 Hz: 20200402-205947_chrome

At 60 Hz: 20200402-210018_chrome

hybridherbst avatar Apr 02 '20 19:04 hybridherbst

One note: while #1169 should fix performance for dual-GPU systems (most Optimus laptops probably), the other part of this issue was the memory leaks and crashes that occured. These probably still happen the same on lower-end GPUs. Have you looked into those as well @elalish?

hybridherbst avatar May 13 '20 19:05 hybridherbst

@soraryu I have attempted, but haven't met with much success yet. If you manage to find a potential source, let me know and I'll look into it. Chrome's memory info is not making anything particularly clear to me.

elalish avatar May 13 '20 19:05 elalish

@cdata I still have the same issues, but it happens after changing the src with 5 GLB models. Chrome crashes on Android and Safari just reloads the page on iOS. They are loaded in cycle, but each time the RAM fills up by a large amount. One model is about 5 MB, but Chrome memory goes up like 100 MB. I've also opened an issue https://github.com/google/model-viewer/issues/1674

TheDino000 avatar Oct 28 '20 13:10 TheDino000