This guide documents how Microverse keeps CPU, energy impact, and memory usage low while preserving real-time system metrics.
- Keep average process CPU low during normal use.
- Reduce Energy Impact by minimizing unnecessary wake-ups.
- Keep resident memory stable and avoid allocation churn.
- Preserve metric accuracy vs macOS Activity Monitor.
Use Activity Monitor to validate real app behavior:
% CPU(CPU tab)Energy Impactand12 hr Power(Energy tab)MemoryandIdle Wake Ups(CPU/Memory tabs)
Filter by Microverse, let the app settle for at least 2-3 minutes, and test both:
- Idle state (no active interaction)
- Active state (open popover, switch tabs, interact with widgets/notch)
Microverse includes a release-mode benchmark executable:
make benchmarkIt benchmarks:
SystemCoresyscall latency (getCPUUsage,getMemoryInfo)- Sequential vs
TaskGroupoverhead for CPU+memory sampling - Publish-suppression helpers (
setIfChanged, quantization) ByteCountFormatterusage patterns
SystemCore.SystemMonitornow usesHOST_CPU_LOAD_INFOtick deltas.- CPU usage is computed from interval deltas, matching Activity Monitor style sampling.
- Counter rollover is handled with 32-bit wrapping arithmetic.
- Memory pressure uses kernel signal
kern.memorystatus_vm_pressure_level. - Heuristic fallback remains for sysctl failure.
speculative_countis not double-counted.
SystemMonitoringServicepolling is ref-counted viaacquireClient()/releaseClient().- Views opt in with
.systemMonitoringActive(...). - Polling stops when no visible surface requires CPU/memory metrics.
- Metrics are quantized before publish (CPU integer bucket; memory rounded fields).
@Publishedupdates occur only when display-visible values change.sampleID: UInt64replaces timestamp-style change signaling.
- Poll loops use
Task.sleep(for:tolerance:)across system/network/audio/battery/weather paths. - Removed hard periodic force-update loop in adaptive notch metric mode.
- Added one-shot dwell retries for adaptive switching so deferred switches are not lost.
- Build and run:
make install-debug
- Validate process-level behavior in Activity Monitor:
- CPU decreases at idle
- Energy Impact decreases at idle
- Idle Wake Ups trends lower
- Run synthetic checks:
make benchmark
- Functional smoke tests:
- CPU/Memory tabs update in near real time
- Notch auto metric switches correctly after dwell windows
- Desktop widget adaptive primary switching still updates correctly
- Benchmark numbers are machine- and thermal-state-dependent.
- Prefer release-mode measurements (
-c release) for any timing conclusion. - Activity Monitor remains the source of truth for end-user process impact.