cg2121 / obs-advanced-timer

GNU General Public License v2.0
188 stars 33 forks source link

High CPU usage because of `script_tick()` #18

Open scy opened 3 years ago

scy commented 3 years ago

This script causes my OBS CPU usage to go up from 2.5 % to 6 %. After looking at the source, I can see that this is because you’re using script_tick() to update the timer once per rendered frame (e.g. 60 times per second if using 60 fps). However, my timer only uses minutes and seconds. 59 out of 60 updates per second are not needed because the text doesn’t change.

My suggestion would be to use timer_add() instead and be called by OBS only as often as required.

I know that it’s possible to use sub-second precision in a timer by changing the format string. Therefore, setting a 1000 ms timer is not always sufficient. Instead, the timer interval should either be manually configurable, or derived automatically depending on the format string placeholders used.

RomanTruba commented 1 year ago

Tried to do this with 250ms interval in 4ad0a62b5866693a754ca2f837688dbe7cf06aad and it works. However, I didn't notice CPU load change.