본문으로 건너뛰기
Skillpedia
모바일 앱7.4k · #13250

swiftui-performance-audit

하는 일

이 스킬은 코드 검토부터 스크롤이 느리거나 업데이트가 무거운 원인 찾기까지 SwiftUI 성능을 점검합니다. 화면이 느리거나 끊기는 iOS 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓SwiftUI 화면이 스크롤하거나 이동할 때 끊길 때.
  • ✓SwiftUI 뷰에서 메모리나 CPU 사용량이 높아 보일 때.
  • ✓SwiftUI 기능의 성능 검토를 받고 싶을 때.

스킬 링크

https://github.com/steipete/agent-scripts/blob/main/skills/swiftui-performance-audit/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/steipete/agent-scripts/blob/main/skills/swiftui-performance-audit/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이 SwiftUI 리스트가 스크롤할 때 끊겨요. 코드를 검토하고 가능성이 높은 원인을 알려 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 뷰 코드에서 넓은 범위의 상태 변경, 뷰 body 안의 무거운 작업 같은 흔한 원인을 찾습니다. 검토 결과가 분명하지 않으면 Instruments에서 프로파일링하는 과정을 안내합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

SwiftUI Performance Audit

Attribution: copied from @Dimillian’s Dimillian/Skills (2025-12-31).

Overview

Audit SwiftUI view performance end-to-end, from instrumentation and baselining to root-cause analysis and concrete remediation steps.

Workflow Decision Tree

  • If the user provides code, start with "Code-First Review."
  • If the user only describes symptoms, ask for minimal code/context, then do "Code-First Review."
  • If code review is inconclusive, go to "Guide the User to Profile" and ask for a trace or screenshots.

1. Code-First Review

Collect:

  • Target view/feature code.
  • Data flow: state, environment, observable models.
  • Symptoms and reproduction steps.

Focus on:

  • View invalidation storms from broad state changes.
  • Unstable identity in lists (id churn, UUID() per render).
  • Heavy work in body (formatting, sorting, image decoding).
  • Layout thrash (deep stacks, GeometryReader, preference chains).
  • Large images without downsampling or resizing.
  • Over-animated hierarchies (implicit animations on large trees).

Provide:

  • Likely root causes with code references.
  • Suggested fixes and refactors.
  • If needed, a minimal repro or instrumentation suggestion.

2. Guide the User to Profile

Explain how to collect data with Instruments:

  • Use the SwiftUI template in Instruments (Release build).
  • Reproduce the exact interaction (scroll, navigation, animation).
  • Capture SwiftUI timeline and Time Profiler.
  • Export or screenshot the relevant lanes and the call tree.

Ask for:

  • Trace export or screenshots of SwiftUI lanes + Time Profiler call tree.
  • Device/OS/build configuration.

3. Analyze and Diagnose

Prioritize likely SwiftUI culprits:

  • View invalidation storms from broad state changes.
  • Unstable identity in lists (id churn, UUID() per render).
  • Heavy work in body (formatting, sorting, image decoding).
  • Layout thrash (deep stacks, GeometryReader, preference chains).
  • Large images without downsampling or resizing.
  • Over-animated hierarchies (implicit animations on large trees).

Summarize findings with evidence from traces/logs.

4. Remediate

Apply targeted fixes:

  • Narrow state scope (@State/@Observable closer to leaf views).
  • Stabilize identities for ForEach and lists.
  • Move heavy work out of body (precompute, cache, @State).
  • Use equatable() or value wrappers for expensive subtrees.
  • Downsample images before rendering.
  • Reduce layout complexity or use fixed sizing where possible.

Common Code Smells (and Fixes)

Look for these patterns during code review.

Expensive formatters in body

var body: some View {
    let number = NumberFormatter() // slow allocation
    let measure = MeasurementFormatter() // slow allocation
    Text(measure.string(from: .init(value: meters, unit: .meters)))
}

Prefer cached formatters in a model or a dedicated helper:

final class DistanceFormatter {
    static let shared = DistanceFormatter()
    let number = NumberFormatter()
    let measure = MeasurementFormatter()
}

Computed properties that do heavy work

var filtered: [Item] {
    items.filter { $0.isEnabled } // runs on every body eval
}

Prefer precompute or cache on change:

@State private var filtered: [Item] = []
// update filtered when inputs change

Sorting/filtering in body or ForEach

List {
    ForEach(items.sorted(by: sortRule)) { item in
        Row(item)
    }
}

Prefer sort once before view updates:

let sortedItems = items.sorted(by: sortRule)

Inline filtering in ForEach

ForEach(items.filter { $0.isEnabled }) { item in
    Row(item)
}

Prefer a prefiltered collection with stable identity.

Unstable identity

ForEach(items, id: \.self) { item in
    Row(item)
}

Avoid id: \.self for non-stable values; use a stable ID.

Image decoding on the main thread

Image(uiImage: UIImage(data: data)!)

Prefer decode/downsample off the main thread and store the result.

Broad dependencies in observable models

@Observable class Model {
    var items: [Item] = []
}

var body: some View {
    Row(isFavorite: model.items.contains(item))
}

Prefer granular view models or per-item state to reduce update fan-out.

5. Verify

Ask the user to re-run the same capture and compare with baseline metrics. Summarize the delta (CPU, frame drops, memory peak) if provided.

Outputs

Provide:

  • A
자주 묻는 질문

항상 프로파일이 필요한가요?

아닙니다. 먼저 코드 검토로 시작하고, 검토 결과가 분명하지 않을 때만 프로파일을 요청합니다.

어떤 흔한 원인을 찾나요?

넓은 범위의 상태 변경, 안정적이지 않은 리스트 식별자, 뷰 body 안의 무거운 작업, 큰 이미지를 찾습니다.

프로파일링은 어떤 빌드로 해야 하나요?

스킬은 프로파일링에 Release 빌드를 사용하도록 권장합니다.

상세 정보

작성자의 원본 설명

SwiftUI performance: render, scroll, CPU/memory, updates, layout, Instruments.

repo: steipete/agent-scripts

인기도

GitHub 스타
7.4k
순위
#13250
라이선스
MIT
업데이트
2026. 10. 30.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬