swiftui-performance-macos

Detect SwiftUI performance anti-patterns in macOS Harness Monitor source code.

Updated Mar 14, 2026
One-click install
npx skills add https://github.com/smykla-skalski/harness --skill swiftui-performance-macos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-performance-macos
Source: https://github.com/smykla-skalski/harness/tree/main/.claude/skills/swiftui-performance-macos
Command: npx skills add https://github.com/smykla-skalski/harness --skill swiftui-performance-macos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill codifies hard performance rules and audit practices to prevent costly SwiftUI regressions in the Harness Monitor macOS app, such as unexpected CPU use from allocator churn, animation feedback loops, and silent perf-test instrumentation failures.

Core Features & Use Cases

  • Body allocation elimination: Guidance to avoid DateFormatter, JSONEncoder, NumberFormatter and other expensive allocations on every view render by using @MainActor cached static lets.
  • Animation and geometry safety: Rules to scope animations narrowly, avoid .repeatForever on always-visible views, and suppress geometry writes during transitions to prevent 60fps feedback loops.
  • Startup and persistence hygiene: Best practices to avoid persisted-state churn on first frame, prevent mirror-state loops for store-backed selection, and hydrate persisted values safely.
  • Instrumentation and testing: Enforces the OSSignposter signpost contract, required perf env vars (HARNESS_MONITOR_KEEP_ANIMATIONS), isolated git worktree audit runs, and xctrace extractor test guidance for reliable Instruments/XCTest perf results.
  • Use cases: Code reviews of SwiftUI views and animations, writing XCTest perf tests, running Instruments audits, and validating startup/restoration flows.

Quick Start

Run the Harness Monitor Instruments audit from an isolated worktree with HARNESS_MONITOR_KEEP_ANIMATIONS=1 to confirm no formatter allocations, geometry feedback loops, or unintended repeatForever animations occur.

Frequently Asked Questions about swiftui-performance-macos

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent formatter allocations in SwiftUI view bodies on macOS?

Prevent formatter allocations in SwiftUI view bodies by caching expensive instances like DateFormatter and NumberFormatter using @MainActor static let properties, avoiding new allocations on every view render.

Why does my SwiftUI macOS app have high CPU usage during animations?

High CPU usage during SwiftUI animations often stems from geometry writes during transitions or .repeatForever on always-visible views, creating 60fps feedback loops that require scoping animations narrowly to resolve.

How do I run an Instruments audit for SwiftUI performance regressions?

Run an Instruments audit for SwiftUI performance from an isolated git worktree with HARNESS_MONITOR_KEEP_ANIMATIONS=1, using the io.harnessmonitor/perf OSSignposter contract to detect formatter allocations and geometry feedback loops.

What's the best way to write XCTest perf tests for SwiftUI macOS apps?

Write XCTest perf tests for SwiftUI macOS apps by enforcing the OSSignposter signpost contract, setting required environment variables like HARNESS_MONITOR_KEEP_ANIMATIONS, and following xctrace extractor test guidance for reliable results.

When do I need to suppress geometry writes in SwiftUI?

Suppress geometry writes in SwiftUI during animation transitions and view restoration to prevent mirror-state loops and 60fps feedback loops, ensuring persisted state hydrates safely without churn on the first frame.

Does this SwiftUI performance guidance apply to iOS or only macOS?

This SwiftUI performance guidance targets macOS specifically, codifying hard rules for the Harness Monitor macOS app including @MainActor cached formatters, animation scoping, and XCTest perf test instrumentation tailored to macOS workflows.