Back to Skills

swift-performance

verified

Optimize SwiftUI and Swift app performance with Instruments profiling, lazy loading, memory management, and view optimization. Use when diagnosing slow UI, fixing memory leaks, optimizing scroll performance, or reducing app launch time.

View on GitHub

Marketplace

fusengine-plugins

fusengine/agents

Plugin

fuse-swift-apple-expert

development

Repository

fusengine/agents

plugins/swift-apple-expert/skills/swift-performance/SKILL.md

Last Verified

January 22, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/fusengine/agents/blob/main/plugins/swift-apple-expert/skills/swift-performance/SKILL.md -a claude-code --skill swift-performance

Installation paths:

Claude
.claude/skills/swift-performance/
Powered by add-skill CLI

Instructions

# Swift Performance Optimization

## SwiftUI View Optimization

```swift
// ❌ BAD - Recreates formatter every render
struct BadView: View {
    var body: some View {
        Text(Date(), formatter: DateFormatter()) // New instance each time!
    }
}

// ✅ GOOD - Cached formatter
struct GoodView: View {
    private static let formatter: DateFormatter = {
        let f = DateFormatter()
        f.dateStyle = .medium
        return f
    }()

    var body: some View {
        Text(Date(), formatter: Self.formatter)
    }
}

// ✅ Use Equatable to prevent unnecessary updates
struct ItemView: View, Equatable {
    let item: Item

    static func == (lhs: Self, rhs: Self) -> Bool {
        lhs.item.id == rhs.item.id
    }

    var body: some View {
        Text(item.name)
    }
}
```

## Lazy Loading

```swift
// ✅ LazyVStack for long lists
ScrollView {
    LazyVStack(spacing: 16) {
        ForEach(items) { item in
            ItemRow(item: item)
        }
    }
}

// ✅ LazyView wrapper for heavy views
struct LazyView<Content: View>: View {
    let build: () -> Content

    init(_ build: @autoclosure @escaping () -> Content) {
        self.build = build
    }

    var body: Content {
        build()
    }
}

// Usage - defers initialization
NavigationLink {
    LazyView(HeavyDetailView(item: item))
} label: {
    Text(item.name)
}
```

## Memory Management

```swift
// ✅ Avoid retain cycles with weak references
class ViewModel: ObservableObject {
    private var cancellables = Set<AnyCancellable>()

    func observe() {
        NotificationCenter.default
            .publisher(for: .someNotification)
            .sink { [weak self] _ in
                self?.handleNotification()
            }
            .store(in: &cancellables)
    }
}

// ✅ Use value types when possible
struct User: Sendable {  // Struct, not class
    let id: UUID
    let name: String
}

// ✅ Image caching
actor ImageCache {
    private var cache = NSCache<NSString, UIImage>()

    func image(for url: 

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
3344 chars