Blog

Why macOS drew my Retina menu bar icons at 1x

A status item drawn 12 times at 1x and 7 times at 2x, a universal binary cut from 16 MB to 7.8 MB, and an idle CPU number that refused to move. Notes from building AirStats 1.7.

18 November 20263 min readMacBook Pro · M3 Pro · 18 GBmacOS 267.8 MB universal · 2.4 MB dmg

AirStats 1.7 started with GitHub issue #39, a screenshot of a blurry globe icon in the menu bar's Icon & Text style, which draws an SF Symbol beside the number.

MenuBarContentView rasterises SF Symbols into an NSBitmapImageRep and caches bitmaps by scale. It read context.ctm.a, which I expected to be 2 on a 2x Retina screen.

Twelve draws at 1x, seven at 2x

A probe status item on a Retina screen logged 12 draws at CTM scale 1 and 7 at scale 2. One pass draws into a recording context with an identity CTM, a == 1, while userSpaceToDeviceSpaceTransform.a is 2. Keying the cache by context.ctm.a saved that 1x bitmap and drew SF Symbols at half resolution.

window?.backingScaleFactor returns nil during offscreen screenshot renders, and hardcoding 2 blurs hairlines on a 1x display. Reading the device transform fixed all 15 Icon & Text readouts in live menu bar screenshots comparing 1.6 and the fixed build:

let scale = max(abs(context.userSpaceToDeviceSpaceTransform.a), 1)

Adding Intel and making the app smaller anyway

PR #38 added an Intel slice for a universal binary. Five changes brought 1.7 below the arm64-only 1.6 release:

  • Stripping the symbol table. Symbols took 6.4 MB per slice versus 2.8 MB stripped. Release builds run dsymutil then strip -x, shipping a 6.7 MB zipped dSYM beside each DMG.
  • Compiling with -Osize instead of -O. Machine code shrank 18%. The heaviest Swift on the sampling path takes a few microseconds; collectors spend their time waiting on the kernel and the SMC.
  • Pruning Sparkle.framework. Release builds remove Headers, PrivateHeaders, and Modules from the bundled framework.
  • Shrinking the logo asset. Shipping the logo at 256 px in gray plus alpha cut it from 158 KB to 9 KB.
  • Compressing the DMG with LZMA. Switching dmgbuild to ULMO cut the DMG from 3.7 MB to 2.4 MB. macOS supports ULMO since 10.15, and AirStats requires macOS 14.

App bundleon disk

1.7 universal7.8 MB
1.6 arm64-only9.4 MB
1.7 before size work16 MB

Disk imagedownload

1.7 universal2.4 MB
1.6 arm64-only3.0 MB
1.7 before size work5.5 MB

Switching dmgbuild to LZMA format ULMO cut the final DMG from 3.7 MB to 2.4 MB.

CPU after closing the panel

AirStats keeps its panel window alive for two minutes after close so reopening is instant. While hidden, its SwiftUI tree kept observing the sampling engine and re-rendering every module and chart each tick. An isPresented flag now swaps the root view for a 1 pt tall Color.clear after fade-out, cutting two-minute post-close CPU across two runs from 1.12% and 1.23% to 0.58% and 0.43%.

Idle CPU did not move, and why

Closed-panel idle CPU stayed at 0.47% and 0.53% before versus 0.47% and 0.52% after across two runs, because two thirds of that cost is AppKit redrawing the menu bar item whenever its readout changes. To skip redraws when nothing visible changed, graph series now build only for graph styles, and the bar style rounds fill levels to a whole percent so minor sensor drift does not redraw every sample.

Reading only what is on screen

Collectors now read only visible fields, and thread count refreshes only while the panel shows it.

CollectorStateBeforeAfterChange
TemperatureMenu bar only4.4 ms2.6 msReads CPU sensors only and skips the power adapter lookup
PowerPanel closed1.9 ms1.2 msReads battery health only while the panel shows it
Wi-FiPanel open7.4 ms3.8 msQueries only the Wi-Fi fields shown on screen

Auditing closed-panel behaviour also fixed a history bug where suspended sources repeated their last reading every tick, drawing flat lines across the 24-hour network, disk, and memory charts while the panel was shut.

Per-process watts and narrower menu bar pairs

Top Processes now sorts by CPU, disk, or energy, one of several features drawing on two forks of the MIT-licensed project. Watts come from ri_energy_nj nanojoule deltas in proc_pid_rusage with RUSAGE_INFO_V6. In a yes load test, AirStats reported 3.1 W for yes versus 2.9 W from an independent tool summing the same kernel counter, and a new summary line at the top of the panel read CPU 97%, yes 90%.

In the menu bar, a stacked pair style fits upload and download, or disk read and write, in one slot, cutting those four readouts from 312 pt to 152 pt. Disk Usage can also draw as a bar.

Testing an app that never quits

Build 1.7 passed 320 unit tests plus Thread Sanitizer and Address Sanitizer runs. Under combined CPU, disk, and network load, the stacked menu bar item held a constant width across 30 captures, and memory stayed at 34 MB across 60 rapid panel open and close cycles.

Tested against the live appcast, the 1.6 GitHub release found 1.7, verified its EdDSA signature, and staged and installed the update on quit. Because a menu bar app started at login rarely quits, 1.7 also installs staged updates when the screen locks or the display sleeps.

AirStats 1.7 is available at airstats.app, and the source is on GitHub.

AirStats

Sixteen metrics in your menu bar for 0.046% CPU. Free and open source.

Download for Mac

MacBook fan running with low CPU? What to check on Apple silicon