Skip to content

Cut idle CPU on battery about 8x without dropping features - #3

Merged
arshdwani merged 1 commit into
mainfrom
battery-idle-cost
Oct 28, 2026
Merged

arshdwani merged 1 commit into
mainfrom
battery-idle-cost

Conversation

@arshdwani

Copy link
Copy Markdown
Owner

What

With the panel closed on battery (the all-day case), Dynamo used ~51 ms of CPU per minute in 1.6; it now uses ~6. No features removed.

Panel closed, on battery 1.6 This PR
Daemon (side by side, 295 s, proc_pid_rusage) 33.3 ms/min 2.95 ms/min
App (5 min each) 18 ms/min 3.1 ms/min
  • Essentials-only battery read (BatteryInfo.read(essentialsOnly:)): 9 keys instead of the whole AppleSmartBattery entry, 0.25 vs 1.6 ms on a cold wakeup. Used by the daemon and by the app while its panel is closed; the open panel still reads everything.
  • Daemon checks every 30 s on battery, every 5 s on power as before. Power source notifications (only a change in ExternalConnected) and a watch on config.json trigger a check at once, so settings now apply in ~0.3 s instead of up to 5 s.
  • Config is parsed again only when its mtime or size changed (0.2 → 0.01 ms).
  • Status heartbeat touches the file instead of rewriting it when nothing changed (1.6 ms → a utimes); DaemonStatus.load counts the file's date as updatedAt.
  • App polls every 60 s instead of 20 s while closed; battery notifications still update the icon at once.

Checked

  • ./build.sh test: all pass, including a new check that the essentials-only read matches the full read (skipped without a battery, as on CI).
  • Old and new daemons run side by side as a user against private data dirs: new reacted to a config change in ~0.3 s (old: next 5 s tick), consumed the request and cleared it; heartbeat every 30–36 s; the CLI still reports the service running when the JSON's updatedAt is 91 s old but the file was touched 25 s ago.
  • Not verified: the immediate check on plugging in (no charger access); the 30 s check covers it, and charging state is already right before plugging in.

Measured over 5 minutes on battery with the panel closed: the daemon went
from 33.3 to 2.95 ms of CPU per minute, the app from 18 to 3.1.

- Battery reads take only the 9 keys the daemon and menu bar icon use,
  instead of copying the whole AppleSmartBattery entry (0.25 vs 1.6 ms when
  cold). The open panel still reads everything.
- The daemon checks every 30 s on battery, where nothing charges, and every
  5 s on power as before. Plugging in or unplugging (power source
  notifications) and config changes (a file watch) trigger a check at once,
  so settings now apply in ~0.3 s instead of up to 5 s.
- Config is parsed again only when the file's mtime or size changed.
- An unchanged status is refreshed by touching the file instead of rewriting
  it (1.6 ms); DaemonStatus.load counts the file's date as updatedAt.
- The app polls every 60 s instead of 20 s while the panel is closed.
@arshdwani
arshdwani merged commit 022aa40 into main Oct 28, 2026
2 checks passed
@arshdwani
arshdwani deleted the battery-idle-cost branch October 28, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant