SPB Git

Repository Public License

performance.md 16.5 KB

# Performance and overhead

A monitor that is itself a noticeable load distorts what it measures. This document describes how ORIX Monitor keeps its overhead bounded by design, and how that overhead is measured. Measured figures are inserted from real runs; none are estimated here.

# Measured results

# Measured results — 2026-11-21, version 1.0.0 (build 1)

# Collectors and store (swift run -c release orix-probe --bench)

Operation Median 95th percentile Calls
CPU sample (all cores) 0.005 ms 0.008 ms 200
Memory sample 0.006 ms 0.007 ms 200
Disk activity (block devices) 0.13 ms 0.15 ms 100
Power and battery 0.37 ms 0.44 ms 50
GPU statistics (best effort) 0.78 ms 0.87 ms 100
Network interfaces and addresses 1.02 ms 1.22 ms 100
Volumes (every 30 s in the app) 16.4 ms 19.7 ms 30
Process table, 5,007 processes 22.3 ms 39.7 ms 20
Store operation (in-memory database) Result
Ingest one simulated day: 43,200 ticks × 27 metrics = 1,166,400 values, flushed every 15 ticks 1.22 s in total, 28 µs per tick
Query 1 hour of raw samples, downsampled to 450 points 0.29 ms
Query 24 hours from the minute tier, 480 points 0.32 ms
Query 24 hours from the hour tier, 24 points 0.06 ms

The process table is by far the most expensive collector, which is why it is sampled half as often as the rest. The test Mac was running about 5,000 processes at the time (simulators and builds); a typical Mac runs several hundred.

# The app measured on itself (Scripts/bench.sh)

Page shown Sampling interval Measured for CPU, share of one core (ps) CPU, self-reported (avg / max) Footprint at the end (footprint) Footprint, self-reported (avg / max)
Dashboard 5 s 90 s 0.87 % 0.85 % / 1.58 % 269 MB 102 MB / 246 MB
Dashboard 2 s (default) 120 s 2.32 % 2.32 % / 5.86 % 80 MB 82 MB / 248 MB
CPU 2 s (default) 90 s 2.47 % 2.42 % / 5.01 % 240 MB 90 MB / 240 MB
Processes (Apps filter) 2 s (default) 90 s 2.14 % 2.18 % / 5.02 % 63 MB 72 MB / 75 MB
CPU 1 s 90 s 4.13 % 4.26 % / 8.17 % 254 MB 243 MB / 255 MB

Conditions: signed Release build 1.0.0 (1), MacBook Pro Mac17,6 (M5 Max, 18 cores), macOS 27.0, on AC power, window on screen, while other builds and simulators were running on the same Mac (about 5,000 processes), which raises the cost of the process table. One run per row; these are single measurements, not averages over several runs.

  • CPU. Roughly 2.1–2.5 % of one core at the default 2 s interval, under 1 % at 5 s, about 4 % at 1 s. On an 18-core Mac, 2.3 % of one core is about 0.13 % of total capacity. The two methods agree to within 0.15 points.
  • Memory. The footprint is not steady: it moves between about 60 MB and about 270 MB during a run. A breakdown with footprint taken at a high point shows about 185 MB of graphics memory owned by the window's layers and about 41 MB of heap; the graphics part is allocated and released by the system and was seen falling back to under 80 MB with nothing changed in the app. Replacing Swift Charts with Canvas drawing did not change it, so it is not the charts. Its cause is not established; it is listed as an open item.
  • Disk. 1,575 samples in the 120 s run produced a 276 kB database (including its write-ahead log); writes happen once every 30 s. Extrapolated linearly, that is about 7.6 MB per hour of raw samples, capped by the 6-hour raw retention; the extrapolation is an estimate.
  • Collection time per sample is shown live in Settings › About; the collectors themselves are timed in §25.
  • A defect found by this benchmark and fixed before release: with Swift Charts animating between samples, the CPU page at 1 s measured 10.1 % of one core. Live charts now redraw once per sample on a Canvas; the same measurement is 4.1 %.
  • Not measured: energy impact, the menu-bar-only state (window closed), and behaviour on battery (where the default interval doubles).

# Overhead design

# One sampling loop

TelemetryEngine.start() creates a single Task that calls tick() and then sleeps. There is one wake-up per interval for all collectors, not one timer per metric. The sleep carries a 10 % tolerance (Task.sleep(for:tolerance:)), which lets the system coalesce the wake-up with other timers.

All work of a tick — reading counters, normalising, evaluating alerts, buffering for the store — runs on the engine actor, off the main thread. The main actor only receives the finished TelemetrySnapshot.

# Tiered intervals

Readings are grouped by cost and by how fast they change (defaults from TelemetryConfiguration):

Tier Default What runs Why
Fast 2 s CPU ticks, VM statistics, block-device counters, interface counters, GPU statistics, thermal state, own rusage Cheap calls on values that change continuously
Process 4 s Full process table: several system calls per process Cost grows with the number of processes
Slow 30 s Mounted volumes (file-system and DiskArbitration queries), power sources and the battery registry entry Values change slowly; the calls are comparatively heavy
Flush 30 s One SQLite transaction Disk writes are batched

The slow tier is event-driven as well as periodic: power, thermal, mount and network-path notifications invalidate it, so a long period does not mean a stale reading after a change.

# Adaptive interval

SchedulerMath.effectiveInterval stretches the fast tier when less precision is needed:

Condition Effect (defaults)
No regular window visible (menu bar only) 2 s → 5 s (backgroundInterval)
On battery or in Low Power Mode, battery saver on interval × 2
Both 10 s

The process tier is stretched by the same factor. "Visible" means a titled, normal-level window that is on screen and not occluded (MonitorModel.updateForeground), so a window fully hidden behind others counts as background.

# Buffered writes

TimeSeriesStore.append only appends to in-memory arrays and updates running minute and hour aggregates. Nothing touches the disk until flush, which the engine calls every 30 s:

  • all pending raw rows and all aggregates go into one BEGIN IMMEDIATE … COMMIT transaction with prepared statements that are reset and reused per row;
  • the database runs in WAL mode with synchronous=NORMAL;
  • pruning runs at most once an hour, followed by PRAGMA incremental_vacuum rather than a full VACUUM.

Minute and hour aggregates are maintained incrementally as samples arrive; no background job re-reads raw data to build them.

# One-slot snapshot stream

TelemetryEngine.snapshots() creates its AsyncStream with .bufferingNewest(1). If the interface is busy when a snapshot is produced, the next one replaces it. Snapshots can never queue up behind a slow consumer, and memory use does not depend on how fast the UI drains them.

# Bounded in-memory window

MonitorModel.liveCapacity is 150 samples. The model keeps at most 150 points per stored metric and 150 rows of per-core loads for live charts; older points are dropped as new ones arrive. At the default 2 s interval the window covers five minutes. Longer views are served from the store on demand (History, Reports, Insights), with a point budget per query (480, 360 and 2000 respectively), so the amount of data handed to a chart is bounded regardless of the time range.

Other bounded structures: the Processes inspector keeps 120 points for the selected process only; recent network-change events are capped at 50 in memory; the menu-bar mini chart uses the last 13 values.

# Caches in the collectors

Cache Avoids
Executable path per (PID, start time) in ProcessCollector Calling proc_pidpath for every process on every process tick; pruned when it exceeds twice the number of live PIDs
User name per UID Repeated getpwuid lookups
Hardware-port map in NetworkCollector, refreshed at most every 60 s Calling SCNetworkInterfaceCopyAll on every tick
Mach timebase read once per ProcessCollector Repeated mach_timebase_info calls
Page size and physical memory read once per MemoryCollector Repeated sysctl calls

Static information (SystemInfo, Metal devices, the capability table) is read once at launch.

# Work done only on demand

Work Trigger
Findings analysis Every 300 s, or the "Analyse Now" / "Refresh Insights" commands
Wi-Fi link and DNS configuration Every fifth snapshot
Latency test The "Run Test" button only
History queries Opening the History page or changing its range or metric
Report building Opening the Reports page or changing its parameters
PDF rendering Pressing the PDF export button

# Things the app does not do

No collector spawns a subprocess, polls a private framework or holds a privileged connection open. There is no helper process, no network activity, and no per-process history written to disk.

# User-visible controls

Control Location Effect on overhead
Foreground interval (1–10 s) Settings › Sampling Sampling rate while a window is visible
Menu-bar-only interval (2–30 s) Settings › Sampling Sampling rate in the background
Process list interval (2–30 s) Settings › Sampling Cost of the heaviest collector
Volumes and battery interval (10–120 s) Settings › Sampling Slow tier
Battery saver Settings › Sampling Halves the sampling rate on battery and in Low Power Mode
Best-effort readings Settings › Sampling Skips the IORegistry reads for GPU statistics and battery detail
Record history Settings › History Skips buffering and periodic flushes
Pause sampling Toolbar, menu bar panel, Monitor menu (⇧⌘P) tick() returns immediately without sampling
Mini charts in the menu bar Settings › Menu Bar Simpler status image

# Self-measurement

ORIX Monitor measures itself with the same method it uses for every other process, on every tick:

Metric Source Meaning
self.cpu proc_pid_rusage(getpid(), RUSAGE_INFO_V4): Δ(user + system time) / Δ time Percent of one core used by the app over the last interval
self.memory ri_phys_footprint Physical footprint in bytes
collectionTime Monotonic clock around the collector calls in tick() Milliseconds the collectors took for this tick (in the snapshot, not stored)

They are visible in the "ORIX Monitor overhead" dashboard widget and in Settings › About ("ORIX Monitor's own footprint"), and self.cpu / self.memory are stored like any other metric, so the app's overhead has a history and can be reported.

# How overhead is measured

Two tools produce the figures for this document. Both measure the real code on the real machine.

# Scripts/bench.sh — the whole app, externally and from inside

bash
Scripts/build.sh release
Scripts/bench.sh [seconds=120] [section=overview] [interval=2]

Procedure:

  1. Launches dist/ORIX Monitor.app (or ORIX_APP) as an isolated instance: -ORIXUITest YES, a fresh temporary -ORIXDataDir, the requested -ORIXSection and -ORIXInterval, -ApplePersistenceIgnoreState YES.
  2. Waits 10 s so launch work is not counted.
  3. Reads the process's cumulative CPU time with ps -o time=, sleeps for the measurement period, and reads it again.
  4. Reads the resident set size (ps -o rss=) and the physical footprint (footprint).
  5. Ends the instance by PID.
  6. Reads the instance's own SQLite database: count, average and maximum of self.cpu (metric 90) and self.memory (metric 91), excluding the first 10 s of samples; the raw row count and database size.
  7. Prints JSON and saves it as build/bench/<section>-<interval>s.json.

Output fields:

Field Method
external.cpu_percent_of_one_core (cpu time after − before) / wall seconds × 100, from ps
external.rss_mb ps resident set size
external.phys_footprint footprint(1)
self_reported.cpu_percent_of_one_core Samples, average and maximum of the stored self.cpu series
self_reported.memory_footprint_mb Average and maximum of the stored self.memory series
storage.raw_rows, storage.database_bytes, storage.bytes_per_hour_at_this_rate Row count; size of the database plus its WAL; size extrapolated linearly to one hour
machine, power_source sysctl hw.model and machdep.cpu.brand_string, sw_vers, pmset -g batt

Having both an external and a self-reported CPU figure is deliberate: agreement between ps and the app's own self.cpu is a check on the app's per-process CPU arithmetic.

Things to keep in mind when reading a result:

  • The -ORIXInterval argument fixes the interval, sets the background interval to the same value, sets the process interval to twice the value and disables the battery saver. A benchmark at "2 s" therefore samples processes every 4 s, as the defaults do, but does not slow down when the window is hidden.
  • The section matters: a page with live charts redraws on every sample; the benchmark records which section was shown.
  • Samples of the last flush period (up to 30 s) may be missing from the database when the instance is killed; the self-reported averages rest on what was flushed.
  • bytes_per_hour_at_this_rate is a linear extrapolation of a short run. It overstates long-term growth, because raw rows are pruned after the raw retention period and SQLite page allocation is not linear at small sizes.
  • CPU time from ps has a resolution of one hundredth of a second; short runs are correspondingly coarse.
  • Results depend on the Mac, the power source (recorded in the output), the number of running processes and whatever else the machine is doing.

# orix-probe --bench — collectors and store in isolation

bash
cd Packages/ORIXMonitorCore
swift run -c release orix-probe --bench

Prints JSON with:

Key What is timed
cpu, memory 200 calls each of CPUCollector.sample() and MemoryCollector.sample()
disk_activity, network, gpu_statistics 100 calls each
power 50 calls of PowerCollector.sample()
volumes 30 calls of DiskCollector.volumes()
processes 20 calls of ProcessCollector.sample(); process_count records how many processes were running
store_ingest One simulated day at a 2 s interval — 43,200 ticks of every MetricID — appended to an in-memory store with a flush every 15 ticks: total seconds and microseconds per tick
query_1h_raw, query_24h_minute, query_24h_hour Mean time of 20 series(...) queries at 480 points, with the number of points returned
machine Model, chip and macOS version

Per-call results are reported as median_ms and p95_ms over the stated number of iterations.

Caveats: the store benchmark uses an in-memory database, so it measures SQLite and aggregation work but not disk I/O; collector timings are back-to-back calls with warm caches, which is the favourable case; and the process collector's time scales with process_count.

# Live inspection

For a quick look without running a benchmark: add the "ORIX Monitor overhead" widget to a dashboard, or open Settings › About. Both show the current self.cpu, memory footprint and collection time per sample.

# Limitations

  • No performance regression test. Nothing in the test suites asserts an upper bound on CPU, memory or collection time; benchmarks are run manually.
  • Energy is not measured directly. CPU time and footprint are measured; the energy impact of wake-ups, GPU compositing of charts and disk writes is not quantified. The kernel's billed energy for the app is available in the process list but is not part of the benchmark output.
  • Rendering cost is included but not isolated. bench.sh measures the whole process; it does not separate collection from SwiftUI and chart rendering. collectionTime isolates the collectors only.
  • One machine. Figures apply to the Mac they were measured on.
  • The process tier is not suspended when the Processes data is not on screen. The process table also feeds top-process widgets, spike detection and the menu-bar panel.
  • The live window is per metric, so its memory is proportional to the number of stored metrics times 150 points; it is bounded but not shared.
Files main
Menu

Theme