Skip to content
Artem

Keeping a live order book at 60 fps in SwiftUI

1 min read

(Mock post. Replace with your own writing.)

A trading screen can get dozens of price updates per second. Sending each one straight into @Published re-renders the whole list. Here is what helped.

1. Throttle at the edge

updates
    .throttle(for: .milliseconds(100), scheduler: RunLoop.main, latest: true)
    .sink { [weak self] in self?.apply($0) }
    .store(in: &cancellables)

2. Stable identity

Rows keyed by price level, not by array index, so SwiftUI updates rows in place instead of re-inserting them.

3. Measure with Instruments

The SwiftUI template in Instruments shows which views update too often. Measure first, then fix.