A 50,000-item list that stutters on updates

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

Pick the fix

What should you inspect first?

Options
Hint 1 of 1

What work scales with 50,000?

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

Show answer

Answer: A Main-thread sorting, filtering and diffing, identifier stability and cost, and full reloads, in Time Profiler

Correct. Those are the usual culprits at this size.

Why not the others?
  • B The app icon size. It's unrelated to list updates.
  • C Whether the list uses Auto Layout. Layout matters for visible cells, not for 50,000-item updates.
  • D The number of reuse identifiers. Reuse isn't the cost when data changes.

30-second answer

Profile the update itself. Look for sorting, filtering or diffing on the main thread, identifiers that are unstable or expensive to hash, and full reloads where a few items changed. Compute new data off the main actor, use stable ids with diffable snapshots and reconfigure only changed items, and batch rapid updates. In SwiftUI, check the ForEach ids and keep row views cheap.

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

Explain how you fix a stuttering large list.

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

  • Profile the update
  • Off-main data work
  • Stable cheap ids
  • Batch updates

Deep dive

Diffable snapshot diffing is linear but still costly at this size on the main thread.

Hashing large structs as item identifiers is slow; use ids.

Coalesce bursts of changes into one snapshot.

Consider paging the data rather than holding all 50,000.

Common mistakes

  • Using whole model structs as identifiers.
  • Applying a snapshot per change in a burst.

Senior take & follow-ups

Seniors profile, then fix identity, threading and batching.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why are model structs bad identifiers?

    Show hint

    Hashing is expensive, and edits look like delete + insert.

  2. How do you handle bursts?

    Show hint

    Debounce or batch into one snapshot.

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