home / skills / willsigmon / sigstack / performance-expert

performance-expert skill

/plugins/ios-dev/skills/performance-expert

This skill helps iOS developers optimize performance by identifying main thread work, memory leaks, and battery drains using profiling best practices.

npx playbooks add skill willsigmon/sigstack --skill performance-expert

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.2 KB
---
name: Performance Expert
description: iOS performance - main thread blocking, rendering, memory leaks, battery drain, profiling
allowed-tools: Read, Edit, Grep, Glob
---

# Performance Expert

Performance optimization for Leavn iOS app.

## Main Thread Violations
Find heavy work in View body:
```swift
// BAD: In View body
let image = processImage(data) // Blocks UI

// GOOD: In ViewModel, async
Task { processedImage = await processImage(data) }
```

## SwiftUI Rendering
- Use `@Observable` (not @Published) for granular updates
- `EquatableView` for expensive views
- `LazyVStack/LazyHStack` for lists
- `drawingGroup()` for complex graphics

## Memory Issues
- Capture `[weak self]` in closures
- Break retain cycles in delegates
- Use `Instruments > Leaks` to find issues

## Battery/Thermal
- Batch network requests
- Reduce location update frequency
- Use `beginBackgroundTask` sparingly
- Profile with Instruments > Energy Log

## Profiling Commands
```bash
# Time Profile
xcrun xctrace record --template "Time Profiler" --launch -- /path/to/app

# Memory
xcrun xctrace record --template "Leaks" --launch -- /path/to/app
```

Use when: Slow UI, battery drain, memory issues, thermal throttling

Overview

This skill helps diagnose and fix iOS performance problems for SwiftUI apps, focusing on main-thread blocking, rendering inefficiencies, memory leaks, and battery/thermal issues. It provides concrete profiling commands, patterns to avoid, and actionable optimizations to restore smooth UI and reduce resource usage. Use it to prioritize fixes and verify improvements with Instruments.

How this skill works

The skill inspects common hotspots: heavy synchronous work inside SwiftUI view bodies, inefficient rendering patterns, closure retain cycles, and battery-heavy background behavior. It recommends code-level changes (move work to view models, use weak captures, use lazy stacks and drawingGroup) and gives xcrun xctrace commands to capture Time Profiler, Leaks, and Energy traces for root-cause analysis. It also suggests runtime mitigations like batching and throttling updates.

When to use it

  • UI stutters, dropped frames, or janky animations in SwiftUI screens
  • High memory growth or recurring leaks detected in Instruments
  • Fast battery drain, elevated device temperature, or thermal throttling
  • Before shipping performance-sensitive features or after refactors
  • When profiling shows heavy synchronous work on the main thread

Best practices

  • Never perform CPU-heavy or blocking work inside a View body — move it to a ViewModel and run async
  • Prefer @Observable for granular SwiftUI updates and use EquatableView for expensive subviews
  • Use LazyVStack/LazyHStack for long lists to avoid unnecessary view creation
  • Capture [weak self] in closures and break delegate retain cycles to prevent leaks
  • Batch network/location updates and minimize high-frequency background tasks
  • Profile with Instruments (Time Profiler, Leaks, Energy Log) before guessing fixes

Example use cases

  • Detect and remove a CPU-bound image processing call that blocks SwiftUI view rendering
  • Identify a delegate retain cycle causing a persistent memory leak and crash risk
  • Lower battery and thermal impact by batching API calls and reducing location update frequency
  • Optimize a slow scrolling list by converting VStack to LazyVStack and deferring work
  • Validate improvements by recording a Time Profiler trace before and after changes

FAQ

How do I spot main-thread work in SwiftUI?

Look for synchronous processing inside View bodies; move heavy tasks into async ViewModel tasks and verify with Time Profiler traces.

Which Instruments templates should I run first?

Start with Time Profiler for CPU, Leaks for memory issues, and Energy Log for battery/thermal investigation.