3dmol / 3Dmol.js

WebGL accelerated JavaScript molecular graphics library
https://3dmol.org/
Other
794 stars 194 forks source link

use less CPU for animations #784

Closed mhellstr closed 1 month ago

mhellstr commented 5 months ago

This page https://3dmol.org/doc/index.html uses 400% CPU on my machine which seems a bit excessive. The same happens for any animation, which means I'm not comfortable putting them on my website.

It would be nice if there was a way to use less CPU for animations.

dkoes commented 5 months ago

Are you sure the issue is with that page? It has close to zero cpu utilization on my laptop. What browser and operating system are you using?

mhellstr commented 4 months ago

On Linux using chrome or brave the CPU utilization is 400% (on an 8-core machine), with Firefox it is 100%.

On Windows the CPU utilization is much smaller.

It really is that page (or any of my own custom 3dmol animations), since switching away from that tab drops the CPU usage to 0.

dkoes commented 4 months ago

The render update is consistently taking a millisecond or less while the interval is 50ms, so I am at a loss as to why there is high cpu overhead. Very open to any suggestions.

dkoes commented 2 months ago

Is this still an issue? I'm seeing 10% CPU utilization on Chrome/Linux now (less than firefox and not much more than it is using while I am typing this).

mhellstr commented 2 months ago

I upgraded to Chromium: 127.0.6533.88 but the high CPU usage is still there on my Linux machine. (There is no high CPU usage for other types of animations like youtube or animated gifs).

If it is not reproducible for you I have no idea what the problem is.

dkoes commented 2 months ago

Did you upgrade 3dmol to the latest version as well?

dkoes commented 2 months ago

Also, do you see the issue with other webgl animations like https://get.webgl.org/ ?

mhellstr commented 2 months ago

I just viewed the animation in the web docs with a clean cache, but the problem persists. On get.webgl.org the CPU usage is surprisingly high (50%), but not as bad as the 3dmol page (400-500%).

dkoes commented 2 months ago

The get.webgl.org animation is insanely simple. If it is causing 50% cpu utilization then there's definitely something unique to your setup (I assume you don't have 50% CPU with a static webpage), independent of 3dmol, that is causing the issue. Do you have any extra extensions installed? Running dev tools at the same time? Perhaps try with a clean profile.

lithces commented 1 month ago

I have similar issue with Chrome on a Manjaro Linux with 3dmol. It is a laptop with amd 4800u. It becomes irresponsible when opening https://3dmol.csb.pitt.edu/ both using xwayland or wayland. However, I see the slowness only with Chrome based browsers, Firefox is completely fine.

I have another laptop with Intel/Nvida hardware with CachyOS Linux. It is fine with both xwayland and wayland, it is fine with both Chrome and Firefox.

lithces commented 1 month ago

I tried some hacks, enabling Vulkan in Chrome on Wayland, the rendering of 3dmol is fine now.

dkoes commented 1 month ago

This is a good point, if you go to chrome://gpu/ and it says hardware acceleration isn't enabled, that would explain the high CPU usage.

mhellstr commented 1 month ago

Thanks for the info - indeed hardware acceleration wasn't enabled. Enabling it decreases CPU usage from 400% down to 120%, which is still significant but much better.

Since this appears to be some local problem on my machine, I'll close the issue.