v5.0.9-06ab4d1
CPU & battery: stop streaming metrics when nobody's looking
This release cuts background CPU and battery usage by making the pipeline-metrics XPC stream opt-in. Before v5.0.9, opfilter sampled and pushed a PipelineMetricsSnapshot to every connected GUI client every second, regardless of whether anyone was looking at the Metrics screen — quietly burning cycles around the clock and producing a noticeable spike after resume from sleep.
Now opfilter samples and broadcasts only while the Metrics screen is visible. When the window is hidden or any other screen is active, the 1Hz sampling timer is suspended entirely — no sampling, no XPC fan-out, no pipeline_metrics os_log lines. Closing the window tears the subscription down immediately rather than waiting for SwiftUI lifecycle. Auto-resumes on reconnect when the Metrics screen is still active (mirrors v5.0.8 allow-stream resume).
Continues the work started in v5.0.8 (issue #144), which made the allow-event stream opt-in. Together they eliminate the steady-state background XPC traffic that previously kept opfilter busy.
Architecture
Dedicated MetricsBroadcaster (in opfilter/XPC/) owns the metrics subscription set and drives a MetricsTimerControlling collaborator on subscriber-count transitions (0 → 1 starts; 1 → 0 stops). DispatchSourceMetricsTimer is the production adapter, with idempotent start()/stop(). Mirrors the v5.0.8 allow-stream pattern.
Internal
- New protocol
MetricsTimerControllingand adapterDispatchSourceMetricsTimer. XPCServerholds bothEventBroadcasterandMetricsBroadcaster.- New
ServiceProtocolmethods:beginMetricsEventStream/endMetricsEventStream. - New
XPCClientreconnect-resume seam:shouldResumeMetricsStream. - 7 new Swift Testing cases under
@Suite("MetricsBroadcaster")covering subscriber transitions, timer start/stop, idempotency.
Commits
06ab4d1end metrics event stream when window hides763cd21MetricsView subscribes to metrics stream while visibleec21b16wire metrics stream resume on reconnectd182134NavigationState exposes isMetricsScreenActivedacc7eeXPCClient gains beginMetricsEventStream with reconnect resume4e43aacroute metrics push through MetricsBroadcaster, gate timer on subscribers0cd4871add DispatchSourceMetricsTimer adapter for 1Hz metrics0d61335MetricsBroadcaster.broadcast no-ops without subscribersa24bab2cover idempotent metrics endStream84c65d8MetricsBroadcaster.removeClient drops subscription and stops timer682cf36MetricsBroadcaster.endStream stops timer on final unsubscribed326832cover repeat-subscribe leaves metrics timer running once456f97dMetricsBroadcaster.beginStream starts timer on first subscriber7f6ba7fadd MetricsBroadcaster scaffold with timer controllerb9d585cadd MetricsTimerControlling protocol seam