superstar54 / weas-widget

A widget to visualize and edit atomic structures in Jupyter Notebook
https://weas-widget.readthedocs.io/en/latest/index.html
MIT License
19 stars 3 forks source link

100% CPU when running widget in VSCode #48

Closed superstar54 closed 5 months ago

superstar54 commented 5 months ago

When I used the widget in VS Code, I found my computer was slow. I check the cpus, and found the CPU > 100%

Screenshot from 2024-03-26 16-04-39

This value is a measure of the CPU time used by the process, divided by the time the process has been running. It's normalized to a single CPU core, so on multi-core systems, the %CPU value can exceed 100%.

But this made the computer slow, maybe because it was a library, which uses threejs, uses animation even though the image is static.

In Three.js, a common approach for animating or rendering scenes is to use a continuous rendering loop, often implemented with requestAnimationFrame. For dynamic scenes that change over time or with interaction, this is necessary. However, for static scenes or scenes that only need to update on certain events (like user input), continuously rendering can waste resources.

To optimize rendering loops for static scenes or scenes that only require updates on events, you can stop using requestAnimationFrame in a continuous loop and instead only render when needed.
superstar54 commented 5 months ago

weas part fixed in https://github.com/superstar54/weas/pull/2