From a tap to a pixel on screen

Performance Senior Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Order the steps

Order the stages from touch to pixel.

  • The touchscreen detects the touch and the system routes the event to the app
  • Core Animation commits the transaction at the end of the run loop turn
  • The render server renders the layer tree on the GPU
  • The display shows the frame at the next refresh
  • Your handler updates state, marking layout and display
  • The window hit-tests and gesture recognizers run
Hint 1 of 1

Hardware first, display last.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A F E B C D

  1. The touchscreen detects the touch and the system routes the event to the app Hardware and system services deliver events to the foreground app.
  2. The window hit-tests and gesture recognizers run This decides which view and handler receive the touch.
  3. Your handler updates state, marking layout and display Your code runs on the main thread here.
  4. Core Animation commits the transaction at the end of the run loop turn Layer changes are batched into one commit.
  5. The render server renders the layer tree on the GPU Rendering happens in a separate process.
  6. The display shows the frame at the next refresh Pixels change on the display's refresh.

30-second answer

The touchscreen reports a touch; the system routes it to your app's event queue; UIApplication delivers it to the window, which hit-tests to find the view and runs gesture recognizers. Your handler updates state, which marks layout and display as needed. At the end of the run loop turn, Core Animation commits the transaction to the render server, which renders the layer tree on the GPU, and the display shows the frame at the next refresh.

Practise saying it · 60 s. No recording, just a timer

Trace a tap to a pixel.

Say your answer out loud, then check which of these points you covered:

  • Event delivery
  • Hit-testing and gestures
  • Commit
  • Render server and display

Deep dive

Work in your handler delays the commit, causing commit hitches.

The render server runs in a separate process.

SwiftUI changes become layer changes in the same commit.

ProMotion can raise the refresh rate during interaction.

Common mistakes

  • Thinking views draw directly to the screen.
  • Doing heavy work in touch handlers.

Senior take & follow-ups

Seniors connect each stage to the kind of performance problem it causes.

Follow-up questions

Think of your answer first, then open the hint.

  1. Where do commit hitches come from?

    Show hint

    Your app's main-thread work before the commit.

  2. Where do render hitches come from?

    Show hint

    The render server taking too long, for example offscreen passes.

Suggest a fix if something here is wrong or out of date.