Skip to content

Prevent NotificationWatcher freezes and excessive energy use - #1

Open
weimo123 wants to merge 1 commit into
immanuel:mainfrom
weimo123:codex/fix-freeze-energy
Open

Prevent NotificationWatcher freezes and excessive energy use#1
weimo123 wants to merge 1 commit into
immanuel:mainfrom
weimo123:codex/fix-freeze-energy

Conversation

@weimo123

Copy link
Copy Markdown

Problem

NotificationWatcher currently runs a recursive Accessibility-tree traversal from a repeating main-run-loop Timer every 1.5 seconds. Each element is queried through several synchronous cross-process AX calls.

This has two related failure modes:

  • If Notification Center is slow or stops replying, the synchronous AX calls block the app main thread and the menu bar app becomes unresponsive until it is force-quit.
  • Even while idle, the app repeatedly walks the Notification Center tree, causing unnecessary CPU wakeups and high cumulative energy impact.

A process sample of the released 1.0.0 build showed the timer callback on the main thread spending its active samples in NotificationWatcher.collectTexts and AXUIElementCopyAttributeValue IPC.

Changes

  • Move all Notification Center discovery and AX traversal to a serial utility queue.
  • Prefer AX created/window-created events and coalesce event bursts before scanning.
  • Add a lightweight window-fingerprint fallback for macOS versions that do not expose those AX notifications.
  • Avoid repeated full scans while the Notification Center window state is unchanged, with a 30-second safety scan.
  • Set a 0.5-second AX messaging timeout so an unresponsive target cannot block indefinitely.
  • Batch text and child attribute reads with AXUIElementCopyMultipleAttributeValues.
  • Bound traversal depth and element count, and keep Notification Center restart and permission-loss handling.
  • Add scan-throttling tests and bump the patch version to 1.0.1.

Validation

  • make test: 39 passed, 0 failed
  • NotificationWatcher sources compile with strict concurrency warnings treated as errors
  • make app succeeds on macOS 15.7.9 / Apple Silicon
  • Built app launches successfully and the packaged app passes deep strict codesign verification

The OTP extraction behavior itself is unchanged.

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