swift-optimise
Apple Swift/SwiftUI Performance Optimization Best Practices
Comprehensive guide for Swift and SwiftUI performance optimization. Contains 19 rules across 3 categories covering modern concurrency, render performance, and animation performance. Targets iOS 26 / Swift 6.2 with @Observable and Swift 6 strict concurrency.
Clinic Architecture Contract (iOS 26 / Swift 6.2)
All guidance in this skill assumes the clinic modular MVVM-C architecture:
- Feature modules import
Domain+DesignSystemonly (neverData, never sibling features) - App target is the convergence point and owns
DependencyContainer, concrete coordinators, and Route Shell wiring Domainstays pure Swift and defines models plus repository,*Coordinating,ErrorRouting, andAppErrorcontractsDataowns SwiftData/network/sync/retry/background I/O and implements Domain protocols- Read/write flow defaults to stale-while-revalidate reads and optimistic queued writes
- ViewModels call repository protocols directly (no default use-case/interactor layer)
When to Apply
Reference these guidelines when:
- Migrating to Swift 6 strict concurrency (Sendable, actor isolation)
- Replacing Combine publishers with async/await
- Implementing @MainActor isolation and actor-based concurrency
- Decomposing views to reduce state invalidation blast radius
- Optimizing scroll and render performance with lazy containers
- Using Canvas/TimelineView for high-performance rendering
- Profiling with SwiftUI Instruments before optimizing
- Building performant spring animations and transitions
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Concurrency & Async | CRITICAL | conc- |
| 2 | Render & Scroll Performance | HIGH | perf- |
| 3 | Animation Performance | MEDIUM | anim- |
Quick Reference
1. Concurrency & Async (CRITICAL)
conc-combine-to-async- Replace Combine publishers with async/awaitconc-mainactor-isolation- Use @MainActor instead of DispatchQueue.mainconc-swift6-sendable- Adopt Sendable and Swift 6 strict concurrencyconc-task-id-pattern- Use .task(id:) for reactive data loadingconc-actor-for-shared-state- Replace lock-based shared state with actorsconc-asyncsequence-streams- Replace NotificationCenter observers with AsyncSequence
2. Render & Scroll Performance (HIGH)
perf-view-decomposition- Decompose views to limit state invalidation blast radiusperf-instruments-profiling- Profile with SwiftUI Instruments before optimizingperf-lazy-containers- Use lazy containers for large collectionsperf-canvas-timeline- Use Canvas and TimelineView for high-performance renderingperf-drawinggroup- Use drawingGroup for complex graphicsperf-equatable-views- Add Equatable conformance to prevent spurious redrawsperf-task-modifier- Use .task modifier instead of .onAppear for async workperf-async-image- Use AsyncImage with caching strategy for remote images
3. Animation Performance (MEDIUM)
anim-spring- Use spring animations as defaultanim-matchedgeometry- Use matchedGeometryEffect for shared transitionsanim-gesture-driven- Make animations gesture-drivenanim-with-animation- Use withAnimation for state-driven transitionsanim-transition-effects- Apply transition effects for view insertion and removal
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
More from pproenca/dot-skills
zod
Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).
2.0Kclean-architecture
Clean Architecture principles and best practices from Robert C. Martin's book. This skill should be used when designing software systems, reviewing code structure, or refactoring applications to achieve better separation of concerns. Triggers on tasks involving layers, boundaries, dependency direction, entities, use cases, or system architecture.
1.4Kemilkowal-animations
Emil Kowalski's animation best practices for web interfaces. Use when writing, reviewing, or implementing animations in React, CSS, or Framer Motion. Triggers on tasks involving transitions, easing, gestures, toasts, drawers, or motion.
918vitest
Vitest testing framework patterns for test setup, async testing, mocking with vi.*, snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.
907typescript
This skill should be used when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
821nuqs
nuqs (type-safe URL query state) best practices for Next.js applications. This skill should be used when writing, reviewing, or refactoring code that uses nuqs for URL state management. Triggers on tasks involving useQueryState, useQueryStates, search params, URL state, query parameters, nuqs parsers, or Next.js routing with state.
735