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

オープン
#995 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@M4n0x がすでに取り組んでいます。

2026年12月3日 から。

  • #996 @M4n0x による — オープン

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
15/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
macos, swift

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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).

主要言語
Swift
スター
184
フォーク
12
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Seb-GRAF/StableBar のほかの issue

Seb-GRAF/StableBar の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。