Repository navigation
Stop the hidden panel draining the battery; fix the window crash - #1
Merged
Merged
Conversation
The popover's SwiftUI views stayed alive after it closed, and the Energy tab's 30 fps flow-arrow animation kept laying out the whole hidden panel: about 18% CPU around the clock on battery. The panel is now built on open and released on close. The arrows are static: animating them made the popover re-measure the panel every frame (about 20% CPU while open, now 1%). While the panel is closed the app polls every 20 s instead of 3 s, picks up battery changes from power source notifications, and skips pmset, system_profiler and history, which only the panel shows. Opening the window (relaunching the app, or the notch fallback) crashed on macOS 26: preferredContentSize sizing in an NSWindow loops AppKit's constraint pass. Windows now size from the view's bounds. The daemon's 5 s timer gets 1 s of tolerance so its wakeups can coalesce.
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.
Why
Dynamo was using 18–30% of a CPU core around the clock on battery, even with its panel closed (10+ hours of CPU over 17 days of uptime). The cause: the popover's SwiftUI views stayed alive after it closed, and the Energy tab's flow arrows (
TimelineViewat 30 fps) kept laying out the whole hidden panel. It hits anyone whose last tab was Energy, because the battery arrow is always "active" on battery.What changed
App.swift). The popover gets a freshNSHostingControllereach time it opens and drops it inpopoverDidClose. The fallback window is released on close too, and reopens where it was.Views.swift). With.preferredContentSizesizing, every animation frame made the popover re-measure the entire panel (~20% CPU while open). The arrows keep their dashes, colors and direction chevron, but don't move.Model.swift):IOPSNotificationCreateRunLoopSource, so the menu bar icon still updates immediately.pmset,system_profilerand history, which only the panel shows; they load at launch and refresh when the panel opens.App.swift). Opening the window (relaunching from Spotlight/Finder, or the notch fallback) crashed 1.5 on macOS 26.6. AppKit aborted after too many Update Constraints passes, because.preferredContentSizesizing in anNSWindowkeeps re-invalidating constraints. Windows now use.standardBounds; the popover keeps.preferredContentSize.Daemon.swift). The 5 s tick gets 1 s of tolerance so macOS can coalesce its wakeups.Measurements
Average app CPU on an Apple Silicon MacBook on battery, Energy tab, with the same scripted open/close sequence on each build:
Policy tests pass (
./build.sh test), and the build has no warnings.Notes for review
DaemonStatus.isFresh's 60 s window, given the daemon's 20 s heartbeat. Hence 20 s rather than 30..standardBoundsfor the popover too. It cut the animated cost, but it offset the popover 20 pt from the status item, and after closing it sometimes still used CPU. So the popover keeps.preferredContentSize, and the arrows are static instead.ImageRendereronly ever captured a single frame of the animation.