Alexander Steiner
Home
Blog

AVCaptureVideoPreviewLayer startup performance

In the past month I used avfoundation APIs a lot to build a camera feature. On this topic, the internet is full of basic examples but just a few places dive deep into details or deal with specific issues. Apple's AVCam project is one of the best and most modern examples out there. But in the process of adapting these examples to your own architecture, minor things can get missing.

One thing I noticed while implementing the camera preview was the slow startup and some hangs. I profiled it and saw my AVCaptureVideoPreviewLayer ViewRepresentable wrapper took about 500ms to create. That's a long time from a rendering perspective.

Long story short: I was starting my AVCaptureSession before connecting that session to my AVCaptureVideoPreviewLayer. Connecting it first and then starting the session fixed the issue and the UI is much more responsive now.

In the process I was searching for the root cause but didn't find any piece of writing about this. So this is more a reminder to future me about this issue when I encounter it the next time. But maybe I could save you a few minutes too.

Published: February 14, 2026
Tagged with: