Blog

Measuring an App That Freezes the Screen: Three Lessons from Snapdeck

Measurement scene with a record button, a stopwatch and a ruler

After pressing the shortcut, the screen froze for 1.4 to 1.7 seconds, and 78% of that time was PNG encoding. Finding that number was easy. The hard part was trusting the measurements that came after it: the thing I was measuring was a screenshot app, and my measuring tool, my test environment and the data I had to keep private were all the same screen.

Snapdeck is an open-source macOS menu bar app I wrote. Press the shortcut and it grabs what every display is showing, opens a full-screen window on top of it, and lets you pick a region, a window or a display. An editor opens next for arrows, captions and redaction, and you save. It is built with Tauri v2, Rust and React, and screen recording came later through ScreenCaptureKit's SCRecordingOutput. Every rule below came out of a mistake I made while measuring it on real hardware. I ran part of that work with a coding agent, which meant a wrong result could reach me looking like a tidy report.

A time measured in a debug build belongs to a different program

The source of the freeze was clear: capture, encoding and window setup ran one after another on the same thread. macOS insists that windows are created on the main thread, but capture and encoding do not have to live there. Once both moved to a worker thread, the work left on the main thread dropped to 100 to 260 ms and stopped depending on the number of displays.

Since the background image is a temporary file that only lives while you select, I also tried a faster PNG setting. The assumption was that lighter compression means shorter encoding. In fact the Rust image crate already defaulted to fast compression, so the only real change was switching the filter from Adaptive to NoFilter. That made encoding slower, from 1.10 to 1.17 seconds up to 1.37 to 1.80 seconds. Worse, both sides of the comparison had been measured in a debug build.

The rule written into the plan that day is short: encoding time is measured in a release build, on a real 3420x2224 frame, and the format is chosen afterwards. The target number changed too. I was no longer measuring how long a PNG takes to write, but how long it takes from the shortcut to the frozen frame appearing on screen. The answer to that question could just as well be an uncompressed format, as long as it stayed lossless.

The same measurement exposed a user behaviour. When nothing happens on screen for 1.5 seconds, people press the shortcut again. Two presses started two workers, both wrote to the same temporary file at once, the second window failed on a label clash, and the error path closed every window. After two presses the user saw no selection screen at all. The fix was a flag that allows one capture at a time and is cleared even on a panic. No unit test found this bug; seeing the delay in seconds forced the question of what a person does during that time.

If your measuring tool captures the screen, the first data to leak is yours

I wanted a screenshot in the README of a screenshot app. In one session, three attempts captured private windows because a full-screen app was sitting in front, and I deleted all three. Publishing your own screen while promoting your own capture tool is about the worst advertisement such a tool can get.

The fix was to stop photographing the interface and render it instead. pnpm screenshots in the repository renders a made-up analytics page into an image at a fixed size. It then mounts the React components the app actually ships over that image, in headless Chromium. The arrow and the redaction box in the editor are drawn through the real toolbar with real pointer events, and each step is checked against what the status bar says rather than assumed. Two side benefits came with it. The pictures are regenerated from the same page every run, so they cannot quietly drift away from the interface. And the redaction tool has something to redact: fake API keys.

Recording made the same problem bigger. To verify a screen recording you have to make one, and it contains the user's live screen. The rule became: recordings are never opened or watched. Only their numbers are read (bytes, the duration, size and frame rate AVFoundation reports, isPlayable, whether a moov atom exists), and the file is deleted right away. The constraint did not weaken the measurement, it sharpened it. Instead of looking at a video and saying it plays, I had to write 3420x2224 pixels, exactly twice the display's 1710x1112 points.

The rule has a cost. The claim that Snapdeck does not record its own sound cannot be observed on hardware. Listening to the recording is off limits, and the app has no code that plays sound anyway. So the configuration was proven by a unit test, and the plan noted plainly that it was not verified on hardware. Not writing down a measurement you could not take is the half of the rule people forget most.

Do not read a result before proving the recording actually started

In the first hardware pass for recording, the full-screen test returned "no file", and the log had no lines either. On first reading that was a recording failure, but the truth was sneakier: the recording had not failed, it had never started. The first menu click right after launch had not opened the selection screen. The cancel test in the same pass came back "clean", with no recording and no leftovers in the folder. Cancelling a recording that never started also leaves the folder clean. I did not count that result as evidence.

Snapdeck's file contract made the proof cheap. When a recording starts, the final name is claimed with a zero-byte placeholder, the video is written to a hidden temporary file marked .snapdeck-recording- in the save folder, and when recording ends the temporary file is moved over the final name. In the second and third passes, every test first saw both files appear, and only then started measuring. This time the results meant something:

  • Cancel after a proven start: 0 videos, 0 temporary files, 0 placeholders.
  • kill -9 during a recording: 1 temporary file and 1 placeholder left in the folder; both were swept when the app reopened.
  • Stop latency, from the menu click to the file appearing under its final name: 65, 422 and 405 ms. The first value measured was 3.5 seconds, because it included the measuring script's own menu waits.
  • Frame rate 29.2 to 29.3 fps, just under the 30 fps cap.

A measurement can be wrong too, so in the sound stage the measuring script itself got an exam. If it does not call a copy of a video cut in half unplayable, it is invalid and no result taken with it is used. A measurement that cannot recognise a bad sample tells you nothing about a good one.

The measurement that shows the value of this rule best was about stop order. The plan assumed that stopping a recording in the wrong order would produce an unplayable file. I measured three orders on macOS 26.5.2 and it did not. The same two-second recording came out at 1,959,168 bytes and 57 frames in the right order. The reverse order, removing the recording output first, still gave a complete file (2,385,608 bytes). Stopping the capture first produced 206,236 bytes, and all three files had a moov atom.

The cost of the wrong order was not a broken file but about 90% of the content silently gone. A test that only checks whether the file was finalised properly would never have seen this bug.

How to carry these rules into your own project

If you are building an app that works with the screen, the camera or the microphone, these are the five rules I paid for:

  1. Measure time only in a release build. Timings in a debug build belong to a different program.
  2. Make promotional images by rendering real components over a fake page, not by capturing your own screen; you get privacy and reproducibility together.
  3. Do not open test output that contains a user's screen; read its numbers and delete the file.
  4. Before each measurement, prove the event actually started with a trace you can see on disk. "No error" and "nothing happened" produce the same output.
  5. Test your measuring script against a deliberately broken sample; if it cannot recognise the bad, it cannot vouch for the good.

One more note on permissions: Snapdeck is signed ad-hoc rather than with a developer identity, and the signature changes on every build. macOS ties the screen recording permission to the signature, so every new build resets it and granting it again asks for Touch ID. That also means you cannot hand the measurements entirely to an agent: only the owner of the screen can approve the permission prompt. I wrote about how I keep a record of a coding agent's mistakes in a separate post. My other open-source work is on the projects page, and the full tables for these measurements live in the plans in the repository.

macOSTestingPerformance