Reduce CPU use and main-thread IPCs in bar updates, app switching and polling

Open
#995 0 comments 0 reactions 0 assignees View on GitHub

@M4n0x is already working on this.

Since Dec 3, 2026.

  • #996 by @M4n0x — open

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
15/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
macos, swift

Research direction

Start by reviewing the linked pull request #996 and the issue’s proposed hot-path changes. The work spans many components, including BarPresentation, WindowClearance, MenuBarItemMirror, Spaces, QuickToggles, and AudioMonitor; follow the relevant paths and tests from there. Done means reducing the listed redundant work and IPCs without changing user-facing behavior or configuration format.

Written by the indexing model from the issue text.

Description

enhancement

Problem

Several hot paths in StableBar do redundant work or synchronous IPCs on @MainActor:

  • BarPresentation.updatePresentations() re-walks configuration.needsModeConnection, rebuilds per-screen widget lookups and re-resolves every widget's style across every screen whenever any single script or provider updates.
  • WidgetConfiguration.label(output:activeApp:date:) allocates a new DateFormatter and recompiles three ICU patterns on every clock render.
  • HexColor.color allocates a fresh dynamic NSColor closure on every SwiftUI body pass, defeating Color == Color diffing, and StyledShadow runs a shadow pass even when no shadow color is set.
  • WindowClearance re-registers AXObserverAddNotification and schedules all running apps on every activation/unhide, making 5 sequential AX IPCs per window on @MainActor.
  • MenuBarItemMirror runs cropping and per-pixel array-allocating image processing on @MainActor every 2 seconds.
  • Spaces.currentSpaces() queries SLSCopySpacesForWindows for all windows before filtering to layer-0 regular apps and round-trips through binary plist serialization.
  • QuickToggles reads full AudioMonitor(input: true).read() (~30+ CoreAudio IPCs) every second while open just for mic mute, duplicates SCDynamicStore IPv4 and Finder preference syncs, and writes bluetoothAccess unconditionally.
  • MenuBarStrip, BarView, MenuBarAppearance, WorkspaceStore, DockBadges, NativeMetrics, AppMenu and ConfigurationLoader perform avoidable main-thread work or unconditional @Observable writes.

Proposal

Optimize these hot paths without changing any user-facing behavior or configuration format:

  • Precompute static BarPresentation metadata and run incremental per-script updates (falling back to a full pass when cross-widget widgetStyles, barStyle or mode-state demand changes).
  • Cache clock DateFormatters (invalidated on locale/timezone changes) and adaptive HexColor NSColor instances; skip uncolored shadow passes while keeping zero-radius hard shadows.
  • Batch WindowClearance window attributes into one AXUIElementCopyMultipleAttributeValues IPC, scope activation/unhide to the activated app, and retry notification registration only until it succeeds.
  • Move MenuBarItemMirror cropping/pixel work off @MainActor with zero-allocation pixel loops, filter Spaces windows before SkyLight IPCs, add AudioMonitor.isMuted(input:), and guard no-op @Observable / @State writes.

Possible today

None of these are configurable; they happen automatically in normal use.

Related

Continues earlier performance work in #161, #174, #246, #353 and #377.

Triaged by Antigravity (Gemini 4 Neon).

Dominant language
Swift
Stars
184
Forks
12
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Seb-GRAF/StableBar

All issues in Seb-GRAF/StableBar

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.