Community编程与开发github.com

dimillian/swiftui-performance-audit

通过代码审查和架构分析来审计并优化 SwiftUI 运行时性能。适用于诊断 SwiftUI 应用中的渲染缓慢、滚动卡顿、高 CPU/内存使用、过多视图更新或布局抖动等问题,并在仅靠代码审查不足时,为用户自行运行的 Instruments 性能分析提供指导。

swiftui-performance-audit 是什么?

该技能旨在帮助开发者通过代码审查和架构分析来诊断并优化 SwiftUI 应用的运行时性能。它能够识别导致渲染缓慢、滚动卡顿、高 CPU/内存使用、过多视图更新或布局抖动等问题的常见模式和反模式。该技能会分析视图结构、状态管理、依赖注入以及绘图生命周期等关键方面,并针对每个发现的问题提供具体的优化建议。当代码审查不足以确定根因时,该技能会指导用户使用 Instruments(如 Time Profiler 或 SwiftUI Profile template)进行进一步的性能分析。该技能支持所有 SwiftUI 平台(iOS、macOS、watchOS、tvOS),并假设用户对 SwiftUI 的声明式编程模型有基本了解。其核心价值在于将性能审查集成到代码审查流程中,从而在早期发现并解决性能问题,避免后期调试的复杂性。

兼容平台~Claude Code~Codex CLI~Cursor
Part ofMobile
npx skills add https://github.com/dimillian/skills/tree/main/skills/swiftui-performance-audit

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

swiftui-performance-audit 是做什么的?

通过代码审查和架构分析来审计并优化 SwiftUI 运行时性能。适用于诊断 SwiftUI 应用中的渲染缓慢、滚动卡顿、高 CPU/内存使用、过多视图更新或布局抖动等问题,并在仅靠代码审查不足时,为用户自行运行的 Instruments 性能分析提供指导。

概述

该技能帮助您在代码审查阶段识别 SwiftUI 中的性能瓶颈。通过分析视图结构、状态管理和依赖关系,它能够提供具体、可操作的优化建议。当静态分析不足以确定问题根因时,它还会指导您使用 Apple 的 Instruments 工具进行进一步的动态分析。

审计领域

  • 视图更新与渲染:检测导致不必要视图更新的模式,如使用 @State 或 @ObservedObject 不当、复杂的 body 计算或大量 @Published 属性。
  • 布局性能:识别可能导致布局抖动的昂贵布局计算、嵌套 GeometryReader 或复杂的 Layout 协议实现。
  • 内存与资源管理:发现可能导致高内存使用或资源泄漏的大型持久化快照、图像缓存问题以及未释放的闭包捕获。
  • 滚动性能:针对 List、ScrollView 和 LazyVStack 等容器,检查可能导致滚动卡顿的 cell 重用问题、复杂视图层次或昂贵的标识符生成逻辑。
  • 绘图与动画:识别低效的绘图代码(如 Canvas 或 drawRect)、触发过多重绘的动画或导致主线程阻塞的同步操作。

工作流程

  1. 接收请求:用户提供一段 SwiftUI 代码或描述特定性能问题(例如:列表滚动卡顿、点击交互延迟)。
  2. 分析代码:基于上述领域对代码进行静态审计,识别潜在的性能反模式。
  3. 提供建议:针对每个问题,给出具体的优化建议(例如:将 @ObservedObject 替换为 @StateObject、为列表元素使用 Identifiable、简化视图层次等)。
  4. 指导性能分析:如果代码审查无法明确根因,建议用户运行特定的 Instruments 模板(如 SwiftUI Profile、Time Profiler、Core Animation)并指导其关注哪些关键指标。
  5. 输出报告:以清晰的格式(如列表或表格)输出审计结果,包括问题描述、严重程度和建议的修复方案。

支持的平台

  • iOS 14+
  • macOS 11+
  • watchOS 7+
  • tvOS 14+

假设

  • 用户理解 SwiftUI 的基本概念(View、@State、@Binding、ObservableObject 等)。
  • 用户拥有在目标平台上运行应用程序的环境。
  • 在需要进一步分析时,用户能够使用 Xcode 的 Instruments。

示例用法

用户请求:我的 SwiftUI 列表在滚动时非常卡顿,cpu 占用很高。

技能响应:请提供相关视图的代码。我将检查 List 或 ScrollView 的使用、每个列表项的标识以及视图层次结构。如有必要,我会建议转换为使用 LazyVStack 并正确实现 Identifiable 协议,或使用 DiffableDataSource 等替代方案。如果代码层面无法确定原因,请运行 Instruments Time Profiler 并聚焦于 body 计算耗时。

Individual skills in this repo

This repo contains 7 individual skills — each has its own dedicated page.

dimillian/app-store-changelog

Create user-facing App Store release notes by collecting and summarizing all user-impacting changes since the last git tag (or a specified ref). Use when asked to generate a comprehensive release changelog, App Store "What's New" text, or release notes based on git history or tags.

dimillian/ios-debugger-agent

Use XcodeBuildMCP to build, run, launch, and debug the current iOS project on a booted simulator. Trigger when asked to run an iOS app, interact with the simulator UI, inspect on-screen state, capture logs/console output, or diagnose runtime behavior using XcodeBuildMCP tools.

dimillian/macos-spm-app-packaging

Scaffold, build, and package SwiftPM-based macOS apps without an Xcode project. Use when you need a from-scratch macOS app layout, SwiftPM targets/resources, a custom .app bundle assembly script, or signing/notarization/appcast steps outside Xcode.

dimillian/swift-concurrency-expert

Swift Concurrency review and remediation for Swift 6.2+. Use when asked to review Swift Concurrency usage, improve concurrency compliance, or fix Swift concurrency compiler errors in a feature or file. Concrete actions include adding Sendable conformance, applying @MainActor annotations, resolving actor isolation warnings, fixing data race diagnostics, and migrating completion handlers to async/await.

dimillian/swiftui-liquid-glass

Implement, review, or improve SwiftUI features using the iOS 26+ Liquid Glass API. Use when asked to adopt Liquid Glass in new SwiftUI UI, refactor an existing feature to Liquid Glass, or review Liquid Glass usage for correctness, performance, and design alignment.

dimillian/swiftui-ui-patterns

Best practices and example-driven guidance for building SwiftUI views and components, including navigation hierarchies, custom view modifiers, and responsive layouts with stacks and grids. Use when creating or refactoring SwiftUI UI, designing tab architecture with TabView, composing screens with VStack/HStack, managing @State or @Binding, building declarative iOS interfaces, or needing component-specific patterns and examples.

dimillian/swiftui-view-refactor

Refactor and review SwiftUI view files with strong defaults for small dedicated subviews, MV-over-MVVM data flow, stable view trees, explicit dependency injection, and correct Observation usage. Use when cleaning up a SwiftUI view, splitting long bodies, removing inline actions or side effects, reducing computed `some View` helpers, or standardizing `@Observable` and view model initialization patterns.

相关技能