RecPix

Our SwiftUI Video Editor Stuttered. One Moving Line Was the Cause

How we measured and fixed the lag in RecPix’s video editor: a playhead that re-laid out the whole window 60 times a second, and what we learned from Cap’s open-source editor.

Updated November 25, 2026 · 5 min read

We tried our editor next to Cap, an open-source screen recorder, on the same Mac. Cap was buttery smooth; ours felt five times slower. Zooming the timeline while the video played ran at about 20 frames a second. This is how we found the cause and fixed it.

Measure first

Profilers show where time goes, but not how a stutter feels. So we added a small meter: a background thread asks the main thread to answer every 4 ms and records how late each answer is. Any answer later than 16.7 ms is a frame the person sees stutter. A debug-only benchmark then plays a real 65-second project and scripts the things people do: scrub, play, zoom the timeline, drag sliders.

The first numbers:

ActionStalls longer than a frameWorst
Playing447 ms
Scrubbing2055 ms
Zooming the timeline while playing235about 46 ms every frame

The cause: one moving line

The playhead was a SwiftUI view whose position changed on every frame. Because it lived in the same view tree as everything else, each move made SwiftUI lay out the whole window again: the toolbar, which tried several layouts to see which fit, and every block on the timeline. At 60 frames a second, that was most of the main thread.

What Cap does differently

Cap's editor is open source, so we read how it stays smooth instead of guessing. We didn't copy any of its code; we took the ideas:

  • The playhead's position lives outside the UI tree, so moving it never touches layout.
  • Each preview request replaces the previous one. The preview never works through a queue of stale frames.
  • The timeline draws only what is on screen.
  • Following the playhead pauses for a second after you scroll or zoom, so the timeline doesn't fight you.

Our fixes

  1. The playhead is now a Core Animation layer that follows the playback clock directly, and the time readout is a plain text field that does the same. SwiftUI never sees them change.
  2. Seeking chases the newest position. One seek runs at a time; while it runs, only the latest target is kept. When it lands and a newer one is waiting, the next seek starts.
  3. The ruler, click marks and narration lines are single drawings of the visible part, instead of hundreds of small views.
  4. The edit buttons are their own view, so zooming the timeline never rebuilds them.
  5. A shadow and rounded clip sat over the live video, costing an extra GPU pass on every frame. The rounding moved onto the video layer, and the shadow onto a plain shape behind it.

After

ActionStalls longer than a frameWorst
Playing02 ms
Scrubbing08 ms
Zooming the timeline while playing2typical frame 9–11 ms

What we didn't copy

Cap runs its own playback engine: a pool of video readers decoding ahead of the playhead. We measured AVPlayer first. It already delivered 48 preview frames a second while scrubbing and 58 while playing. A decoder pool would add a lot of risk for no visible gain, so we left it out.

Lessons

  • If one thing changes every frame, keep it out of your SwiftUI tree.
  • Measure stalls the way people feel them, on a real project, before and after every change.
  • Reading a good open-source app is faster than guessing. Credit it, and don't copy its code.

All of this shipped in RecPix 0.9.10, along with tracks, clip speed, music and chapters built on the faster timeline.

Your next tutorial starts here

One sentence to your agent. A narrated, captioned video back, ready to post.

or any MCP agent

3 videos free · then pay once · macOS 15 or later