## Performance Optimization

### Measure Before Optimizing

Never optimize without profiling first. Use Instruments.

### Common iOS Bottlenecks

| Area    | Problem                     | Solution                                       |
| ------- | --------------------------- | ---------------------------------------------- |
| SwiftUI | Unnecessary re-renders      | `@State` correctly, equatable, `EquatableView` |
| SwiftUI | Heavy body computation      | Move out of `body`, cache with `@State`        |
| Images  | Large images on main thread | `AsyncImage` or background decoding            |
| Network | No caching                  | `URLCache`, ETag, conditional requests         |
| Memory  | Retain cycles               | `[weak self]`, Instruments Leaks               |
| Layout  | Complex hierarchies         | Flatten, `LazyVStack`/`LazyHStack`             |

### Caching Strategy

1. In-memory: `NSCache`
2. Disk: `FileManager` + Codable
3. Network: `URLCache`
4. Database: CoreData or SwiftData
