Skip to content

Reduce high CPU usage by eliminating redundant cursor geometry calculations - #441

Closed
itradesize wants to merge 0 commit into
vinzdg:mainfrom
itradesize:perf/cursor-geometry-upstream-main
Closed

itradesize wants to merge 0 commit into
vinzdg:mainfrom
itradesize:perf/cursor-geometry-upstream-main

Conversation

@itradesize

Copy link
Copy Markdown

Problem

Codenotch performs repeated geometry and model calculations
during mouse movement, even when the underlying layout has
not changed.

On multi-display setups, each notch controller processes
desktop-wide mouse events, making redundant calculations
particularly expensive.

Runtime CPU profiling identified cursor geometry evaluation
as a major contributor to mouse-related CPU usage.

Changes

This PR reduces redundant calculations within individual
cursor events.

  • Introduces reusable cursor geometry evaluation.
  • Reuses calculated hit regions and layout metrics.
  • Avoids recalculating unchanged geometry multiple times
    during the same cursor event.
  • Refreshes geometry when synchronous model updates can
    affect layout or positioning.
  • Preserves existing hover, tooltip, expansion, and
    interactive-region behavior.

No mouse-event throttling, artificial delays, or animation
quality reductions were introduced.

Performance observations

Observed on an Apple Silicon MacBook Pro with four displays.

| Build | Stationary CPU | Mouse movement CPU |
| Original Debug | 6–8% | 30–43% |
| Release before optimization | ~3.6% | 16–19% |
| Optimized Release | 2.4–5% | ≤7.5% |

The Debug-to-Release improvement comes from compiler
optimization and is not attributed to this PR.

The relevant comparison for this change is between the
two Release builds.

These figures are informal Activity Monitor observations
during normal usage, not controlled benchmarks.

Validation

  • Optimized Release build compiled successfully for arm64.
  • Swift -O and whole-module optimization verified.
  • Application launched successfully.
  • User confirmed correct operation across four displays.
  • Focused geometry regression tests added.
  • Static code review and git diff --check passed.

Automated regression tests were not executed during this
submission preparation.

Compatibility

This optimization is independent of PR #431, which addresses
display reconciliation after sleep/wake.

The changes can be applied directly to upstream main
without requiring that fix.

@itradesize
itradesize requested a review from vinzdg as a code owner October 9, 2026 16:50
@itradesize itradesize closed this Oct 9, 2026
@itradesize
itradesize force-pushed the perf/cursor-geometry-upstream-main branch from a416a03 to bcb2889 Compare October 9, 2026 16:52
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