bwasti / mebm

zero-dependency browser-based video editor
https://bwasti.github.io/mebm/
MIT License
933 stars 73 forks source link

High idle CPU consumption #3

Open narcolepticinsomniac opened 3 years ago

narcolepticinsomniac commented 3 years ago

Tested in Chrome and Firefox stable. Simply loading the page, CPU idles ~20%. Loading a video, CPU spikes dramatically, and takes quite a while, but I suppose at least there's an obvious reason for it. After the video's loaded, idle CPU consumption's even worse, ~30%.

bwasti commented 3 years ago

How are you profiling? I'm not very familiar with JS tools yet.

I suspect it was resize logic living in the render loop. I just hoisted it out and attached the profile results below. Does this fix the issue for you as well?

no video:

Screen Shot 2021-01-24 at 1 31 09 PM

one video, playing:

Screen Shot 2021-01-24 at 1 31 46 PM
narcolepticinsomniac commented 3 years ago

How are you profiling?

Nah man, you'll get nothing fancy or helpful from me. I simply have CoreTemp always running in the system tray, so I immediately notice when idle CPU is higher than expected. When it is, a quick check of Chromium's task manager reveals it's your page consuming said CPU.

To rule out conflicts, I checked your page in fresh profiles of Chromium and Firefox, and see the same. If anything, it's slightly worse in FF.

Does this fix the issue for you as well?

Nope. I see no difference in idle CPU. Presumably, everyone will repro to varying degrees, depending on hardware. I'm testing mainly on a low-end i7 that's a few years old. Oddly enough, I double checked on a pretty ancient Core 2 Quad Q8200 desktop I use as an HTPC, and idle CPU consumption, while still not good, is about half what I see on the i7.

Idle - nothing loaded:

CPU

As you see in the screenshot, seems like GPU is a factor. My best uneducated guess would be that the problem's caused by something canvas/GPU/hardware-acceleration related. Neither computer has any GPU/hardware-acceleration issues in general though, FWIW.