Repository navigation
Conversation
MenuBarExtra renders its label into the status item on every scene update and on every change the label observes, and each render makes macOS repaint the item's snapshot in every menu bar. The label observed AppModel, LiveState and Repository whole, and StrandApp observed AppModel, so every published change paid that cost: about a quarter of a core plus 15% more WindowServer while a strap streamed. The label now observes one Equatable MenuBarReading, published at most once a second and only when it differs from the one on screen. StrandApp holds AppModel through an owner that never publishes. The popover's heart rate uses the same display rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DX23876
pushed a commit
to DX23876/noop
that referenced
this pull request
Nov 8, 2026
Adopted from ryanbr#2889 (by @msff). The menu-bar label observed AppModel, LiveState and Repository whole, and the app scene observed AppModel, so every published change re-rendered the status item, which macOS repaints in every menu bar. While a strap streamed that cost about a quarter of a CPU core plus WindowServer time. The label now observes one MenuBarReading (shown heart rate and link state), updated at most once a second and only when it changes. The app scene holds AppModel through an owner that never publishes; its body reads only the model's subsystems, never its published state. Fork adaptation: the label no longer carries the fork's dashboardPresentationScope (it reads no sleep data); the popover keeps it. The reading is mapped through a closure instead of a function reference for the fork's strict concurrency checking. Not compiled here (no Swift toolchain in this environment). Analysis migration required: no Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015AWc14WNvMmSF4RHP6ww4d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
The macOS menu-bar item now redraws only when the heart rate or link state it shows changes, at most once a second, instead of on every published change of the app's model. Before this, NOOP used about a quarter of a CPU core, plus about 15% more WindowServer, for as long as a strap was streaming.
A 5 s
samplehad the status item's repaint path at the top of the main thread:Cause.
MenuBarExtrarenders its label into the status item's image and title in two cases, whether or not the drawing changed:Each render makes macOS repaint a snapshot ("replicant") of the item for every menu bar it shows in. On one display, macOS 27.2 keeps 8 replicants of the item, 4 light and 4 dark. Each repaint sets the source button's appearance, and SwiftUI's
MenuBarExtraControlleranswers each appearance change with another render.The label observed
AppModel,LiveStateandRepositorywhole, andStrandAppobservedAppModelthrough@StateObject. Between them those objects publish more than a hundred properties, dozens of times a second while a strap streams. Every one of those changes paid the repaint cost.A minimal standalone
MenuBarExtraapp reproduces the mechanism. In it, any publish from an App-level@StateObjectre-renders the label, even when the label reads nothing from that object.Fix.
MenuBarLabelobserves oneEquatablevalue,MenuBarReading: the displayed heart rate and the link state.MenuBarReadingSourcepublishes a new reading at most once a second, keeps the latest reading, and skips any reading equal to the one on screen (MenuBarReading.drawn).StrandAppholdsAppModelthroughAppModelOwner, which never publishes. That keeps@StateObject's build-once guarantee without re-evaluating the scenes on every model change. The scene body reads only the model's subsystems, which arelets, so observing the model gave the scenes nothing.MenuBarReading.displayHR), so the label and popover show the same number; the label can trail the popover by up to a second.What the label shows and how it is tinted are unchanged.
Type of change
How it was tested
swiftcapp,MenuBarExtralabel driven at 20 publishes/s,top -pidover 60 s on a MacBook Air M2):StrandTests/MenuBarReadingTests.swift, 7 tests:removeDuplicatesthrottledebouncein place ofthrottlelatest: falseapp-build.yml.Known limits
StrandPalette.chartStyle, a global that the main window's.chartStyle(_:)modifier sets as it renders. The label no longer re-renders on every published change. So after a Chart style switch, a label whose reading stays the same, such as linked with no heart rate yet, can keep the old style's colour until its reading next changes. While a heart rate streams, the reading changes within seconds.MenuBarContentstill observesAppModel,LiveStateandRepositorywhole. It lives in its own window and is only on screen while open; this was not re-sampled.Unapplied review findings
Strand/MenuBar/MenuBarContent.swift:84— the popover's heart rate can run up to a second ahead of the throttled label.Suggested fix: build
MenuBarReadingSourceonce inAppModelOwner, pass it toMenuBarLabel, inject it intoMenuBarContent, and read the popover's number from it. The popover's number would then move at most once a second.MenuBarReadingSource's wiring has no test of its own. A change that droppedmodel.$bpmorlive.$connectedfrom its inputs would pass every test here. NoStrandTeststest builds anAppModel, because its init startsBLEManagerandRepository, so such a test needs a seam first.From a local review (correctness plus one adversarial reader); run
20261101-220955-5e314cb3.Checklist
android/— not touched: Android has no menu-bar extraStrandDesigntokens — no hardcoded colors, fonts, or spacingdocs/CONTRIBUTING.mdStrand.xcodeproj/) or any secrets/keystoresRelated issues
Refs #2393. That issue covers a neighbouring idle cost, the main window's Liquid animations rendering while the window is hidden. This PR does not touch them.
🤖 Generated with Claude Code