Skip to content

Conversation

@stonerl
Copy link
Contributor

@stonerl stonerl commented Jan 6, 2026

This PR introduces optimizations to reduce the app's energy impact, regarding mouse event handling. This should fix issue #479 and issue #334

  • Conditional Event Monitoring:

    • The mouseMoved event tap is now only enabled when the "Show on Hover" setting is active.
    • This completely eliminates overhead during mouse movement when the feature is disabled.
  • Event Throttling:

    • When "Show on Hover" is enabled, mouseMoved events are now throttled to process only every 5th event.
    • CPU usage is reduced without affecting perceived responsiveness.
  • Optimized Hit-Testing:

    • Reordered hit-test checks to prioritize cheap geometric calculations (bounds, notch) before performing expensive Window Server queries.
    • Implemented a short-lived cache (0.5s) for the menu bar window list to minimize expensive IPC calls to the Window Server while the user is interacting with the menu bar.

- Only enable the `mouseMoved` event tap when the "Show on Hover" setting is enabled.
- This prevents unnecessary event processing on every mouse movement when the feature is disabled, significantly reducing idle CPU usage and energy impact.
- Added observers to dynamically start/stop the event tap when the setting is toggled.
- fixes #479

Signed-off-by: Toni Förster <[email protected]>
- Throttle `mouseMoved` event processing to handle only every 5th event, significantly reducing CPU usage during high-frequency mouse movement.
- Reorder checks in `isMouseInsideEmptyMenuBarSpace` to prioritize cheap geometric calculations over expensive Window Server calls.
- Implement a short-lived cache (0.5s) for the menu bar window list in `isMouseInsideMenuBarItem` to minimize IPC overhead with the Window Server.

Signed-off-by: Toni Förster <[email protected]>
cp09x added a commit to cp09x/icebar that referenced this pull request Jan 24, 2026
Critical Improvements:
1. Safety: Replace force unwraps in Constants.swift with safe defaults
   - Prevents crashes if Info.plist is misconfigured
   - Adds fallbacks: versionString, buildString, bundleIdentifier, etc.

2. Performance: Add removeDuplicates() to overlay panel publishers
   - Prevents unnecessary redraws when applicationMenuFrame hasn't changed
   - Optimizes desktop wallpaper comparison using CGImage data
   - Estimated impact: 30-40% reduction in unnecessary UI updates

3. Performance: Reduce wallpaper polling from 5s to 15s
   - Desktop wallpaper capture is expensive (CGImage creation)
   - 3x reduction in polling frequency
   - Estimated impact: Reduces CPU usage and energy consumption

Build: Verified with xcodebuild - BUILD SUCCEEDED

Based on analysis of:
- Upstream PRs jordanbaird#842, jordanbaird#841 (CPU/memory optimization patterns)
- Code analysis by explore agents (found force unwraps, missing removeDuplicates)
- Oracle strategic planning (prioritized high-impact, low-risk fixes)
cp09x added a commit to cp09x/icebar that referenced this pull request Jan 24, 2026
Performance optimizations from upstream PR jordanbaird#842 patterns:

1. Mouse Event Throttling:
   - Process 1 in 5 mouse moved events (80% reduction)
   - Significantly reduces CPU usage during mouse movement
   - Uses simple counter-based throttling for minimal overhead

2. Window List Caching:
   - Cache menu bar window list for 0.5 seconds
   - Reduces expensive WindowServer IPC calls
   - Hit-testing now uses cached data instead of fresh queries

Combined Impact:
   - Reduced CPU usage during mouse interaction
   - Lower WindowServer communication overhead
   - Smoother app responsiveness
   - Better battery life on laptops

Build: Verified with xcodebuild - BUILD SUCCEEDED
@stonerl stonerl closed this by deleting the head repository Jan 29, 2026
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