1---2name: apple-performance-cleanup3description: Behavior-preserving performance cleanup for Swift, SwiftUI, and Apple app code. Use when simplifying hot paths, startup paths, telemetry, parsing, persistence, rendering, memory behavior, concurrency, leaks, or broad code that must not regress app performance or behavior.4---56# Apple Performance Cleanup78## First Pass910- Identify the hot path, behavior contract, current tests, and measurable risk before refactoring.11- Read the current implementation and call sites before introducing helpers. Do not convert cleanup into a broad rewrite.12- Read `references/performance-cleanup-patterns.md` for startup, parsing, telemetry, rendering, persistence, concurrency, or memory-sensitive work.13- Prefer tiny helper extraction, duplicated-branch removal, and source-contract tests over architecture churn.1415## Rules1617- Preserve behavior first, improve structure second, improve speed only when measured or clearly implied by less work.18- Do not add allocations, main-thread work, logging, synchronization, persistence, or view invalidation inside a hot path without proof.19- Keep optional/missing data semantics intact. Cleanup often breaks edge cases by flattening nil, zero, unavailable, stale, and failed states.20- Avoid broad SwiftUI invalidation. Move derived values, formatting, timers, and expensive work out of body recomputation when needed.21- Treat concurrency fixes as ownership fixes, not warning suppression.22- If the user says stop, stop immediately and report what was verified versus what remains.2324## Validation2526- Run focused unit tests around the exact parsing, timing, state, or rendering contract.27- Use profiling tools when the risk is runtime speed, launch, memory, or UI responsiveness.28- Compare before/after behavior for representative edge cases.29- Keep performance cleanup commits small enough to review.