macos-app-optimizer
Use when analyzing macOS apps for optimization opportunities, improving memory/RAM usage, reducing memory leaks, optimizing SwiftUI performance, or analyzing Swift code for efficiency. Load for any macOS app performance analysis or memory optimization task.
What this skill does
# macOS App Optimizer
Analyze macOS applications for performance and memory optimization opportunities.
## Core Principle: RAM Optimization
Memory optimization is the primary focus. Every analysis should identify:
- Memory leaks (retain cycles, unbalanced alloc/free)
- Unnecessary object retention
- Inefficient data structures
- Cached data that should be purged
- Large objects that could be lazy-loaded
## Workflow
### 1. Analyze Codebase Structure
```bash
# Identify main components
find . -name "*.swift" -type f | head -20
# Check for common patterns
grep -r "@Published\|@State\|@ObservedObject" --include="*.swift"
# Find potential retain cycles
grep -r "closure\|weak\|unowned" --include="*.swift"
```
### 2. Check Context7 for Apple Best Practices
Use Context7 to query relevant Apple documentation:
| Use Case | Context7 Query |
|----------|----------------|
| SwiftUI performance | `/swiftlang/swift` "SwiftUI performance view redraw" |
| Memory management | `/swiftlang/swift` "ARC memory management retain cycles" |
| Async operations | `/swiftlang/swift` "async await memory management" |
| SwiftData optimization | Search for SwiftData-specific docs |
| Foundation patterns | `/apple/foundation` "memory efficient collections" |
### 3. Analyze Common Memory Issues
| Issue | Pattern to Find | Fix |
|-------|-----------------|-----|
| Retain cycles | Closures capturing `self` | Use `[weak self]` |
| @Published bloat | Too many published properties | Consolidate or use computed |
| Large images | Image literals, large assets | Lazy load, downsample |
| Memory leaks | Classes without deinit | Add `deinit` to verify |
| Cached data | Static caches without purge | LRU cache, memory pressure handlers |
### 4. Check Instruments-Ready Patterns
Ensure code is instrumentable:
```swift
// Good - trackable
class ViewModel: ObservableObject {
deinit { print("ViewModel deallocated") }
}
// Bad - can't track lifecycle
class ViewModel {
// No deinit
}
```
### 5. Specific Optimizations by Component
#### SwiftUI Views
- Use `@State` for local view state only
- Prefer `let` over `var` for view body
- Extract expensive computations to separate functions
- Use `LazyVStack`/`LazyHStack` for long lists
#### ViewModels
- Use `@Observable` instead of `ObservableObject` (Swift 5.9+)
- Minimize `@Published` properties
- Avoid storing large data directly (use IDs, fetch separately)
#### Networking
- Cancel tasks on deinit
- Stream large responses instead of buffering
- Use `URLSession.shared` (singleton)
#### Persistence
- Use SwiftData with proper faulting
- Avoid loading entire datasets into memory
- Consider Core Data for complex queries
### 6. Memory Pressure Handling
```swift
// Listen for memory warnings
NotificationCenter.default.addObserver(
forName: NSApplication.didReceiveMemoryWarningNotification,
object: nil,
queue: .main
) { _ in
// Purge caches, clear non-essential data
}
```
### 7. Output Format
Provide optimization report in this table:
| Priority | Issue | Location | RAM Impact | Fix |
|----------|-------|----------|------------|-----|
| HIGH | Retain cycle in closure | ViewModel.swift:42 | ~5MB/minute | Use `[weak self]` |
| MEDIUM | Unnecessary image caching | ImageLoader.swift:15 | ~50MB | Downsample images |
| LOW | Redundant @Published | SettingsView.swift:8 | ~1KB | Remove `@Published` |
## Quick Reference: Context7 Library IDs
| Library | ID | Use For |
|---------|-----|---------|
| Swift Language | `/swiftlang/swift` | Language patterns, ARC, async |
| Foundation | `/apple/foundation` | Collections, URL, file I/O |
| SwiftUI | Check Apple docs | View optimization |
| SwiftData | Check Apple docs | Persistence patterns |
## Scripts
| Script | Purpose |
|--------|---------|
| scripts/analyze_memory.sh | Find potential memory issues |
| scripts/check_retain_cycles.sh | Detect closure capture patterns |
| scripts/measure_heap.sh | Estimate heap allocation |
Related in Productivity
gitea-workflow
IncludedOrchestrate agile development workflows for Gitea repositories using the tea CLI. Use when working with Gitea-hosted repos and asking to 'run the workflow', 'continue working', 'what's next', 'complete the task cycle', 'start my day', 'end the sprint', 'implement the next task', or wanting guided step-by-step development assistance. Keywords: workflow, orchestrate, agile, task cycle, sprint, daily, implement, review, PR, standup, retrospective, gitea, tea.
microsoft-graph-gateway
IncludedRoute Microsoft Graph work in this workspace. Use when users want to read or write Outlook mail, calendar events, contacts, OneDrive or SharePoint files, Teams, Planner, To Do, users, groups, directory data, or arbitrary Microsoft Graph endpoints from VS Code. Prefer WorkIQ for common read scenarios. Use Microsoft Graph for write actions and gap-read scenarios that need exact Graph properties, filters, permissions, or endpoints.
copilotkit
IncludedUse when building with CopilotKit — setup, development, integrations, debugging, upgrading, or contributing. Routes to the appropriate specialized skill based on the task.
wordly-wisdom
IncludedProvides calibrated decision analysis using Charlie Munger-style multiple mental models, inversion, incentive mapping, circle-of-competence checks, misjudgment audits, second-order effects, and forecast updates. Use when the user asks for an oracle take, a hard call, a decision memo, a premortem, an outside view, a red-team, a sanity-check, what am I missing, think this through, or wants a strategy, hire, investment, plan, product, partnership, or major life choice analysed. Avoid for simple factual lookups or time-sensitive legal, medical, or market questions without fresh evidence.
swain-session
IncludedSession management and project status dashboard. Owns the full session lifecycle (start/work/close/resume), focus lane, bookmarks, worktree detection, and tab naming. Also serves as the project status dashboard — shows active epics, progress, actionable next steps, blocked items, tasks, GitHub issues, and recommendations. Worktree creation is deferred to swain-do task dispatch (SPEC-195). Triggers on: 'session', 'status', 'what's next', 'dashboard', 'overview', 'where are we', 'what should I work on', 'show me priorities', 'bookmark', 'focus on', 'session info'.
gandi
IncludedComprehensive Gandi domain registrar integration for domain and DNS management. Register and manage domains, create/update/delete DNS records (A, AAAA, CNAME, MX, TXT, SRV, and more), configure email forwarding and aliases, check SSL certificate status, create DNS snapshots for safe rollback, bulk update zone files, and monitor domain expiration. Supports multi-domain management, zone file import/export, and automated DNS backups. Includes both read-only and destructive operations with safety controls.