netik / UTCMenuClock

Simple Objective-C based Menu Clock for Mac OS X. Displays the UTC time in the menubar and nothing more.
Apache License 2.0
242 stars 46 forks source link

Adjust NSTimer to reduce CPU usage #18

Open davidme-stripe opened 1 year ago

davidme-stripe commented 1 year ago

Hello! Thank you for developing UTCMenuClock, it's a very useful tool! 😄

We've noticed that when "show seconds" is disabled, the time still redraws once per second, potentially impacting battery life. This includes string drawing, XPC calls to cfprefsd, and icu date formatting.

To fix this, I've configured the NSTimer to only fire once per minute on the minute, reducing CPU usage from ~0.5% to 0%.

I also added a little bit of tolerance (~50ms) when seconds are enabled, which should allow the CPU to sleep between updates.

Before

CleanShot 2023-01-18 at 11 53 08@2x

After

CleanShot 2023-01-18 at 11 53 36@2x