Smooth scrolling in lists

Performance Mid-level Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

Time Profiler shows image decoding and DateFormatter creation inside cellForRow while scrolling. Fix?

Options
Hint 1 of 1

What runs per cell on the main thread?

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

Show answer

Answer: A Decode and downsample images off the main thread, cache them, and reuse a formatter or precompute date strings

Correct. Both main-thread costs leave the scroll path.

Why not the others?
  • B Call reloadData less often. It doesn't change per-cell cost.
  • C Add more cells to the reuse pool. Reuse isn't the bottleneck.
  • D Use a bigger estimated row height. Sizing doesn't fix decoding and formatter costs.

30-second answer

Keep cellForRow cheap: reuse cells, configure from precomputed view data, and never decode images or do I/O there. Load and downsample images asynchronously, prefetch upcoming rows and cancel ones that leave. Use estimated sizes with simple constraints, avoid offscreen rendering such as shadows without a shadowPath, and profile while scrolling on an older device.

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

Explain how you make lists scroll smoothly.

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

  • Cheap cell configuration
  • Async images + prefetch
  • Avoid offscreen rendering
  • Profile on old devices

Deep dive

Precompute strings like formatted dates in the view model.

Use UICollectionView.CellRegistration and content configurations.

Flatten deep view hierarchies inside cells.

In SwiftUI, use List or Lazy stacks with stable ids.

Common mistakes

  • Formatting dates with a new DateFormatter per cell.
  • Synchronous image loading.

Senior take & follow-ups

Seniors profile the scroll, then fix the top offenders in order.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why are DateFormatters expensive?

    Show hint

    They're costly to create; reuse them or use FormatStyle.

  2. What does prefetching give you?

    Show hint

    Time to load data before the cell is visible.

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