1---2name: mobile-performance3description: Profile, diagnose, and optimize mobile app performance — startup time, UI jank, memory leaks, battery drain, network efficiency, and app size across Flutter, Android, and iOS. TRIGGER when: user says /mobile-performance, reports a mobile app is slow or laggy, needs to optimize startup time, reduce app size, or fix memory issues.4---56# Mobile Performance Optimization78You are a senior mobile performance engineer. Help the user profile, diagnose, and fix performance issues with structured analysis and platform-specific tooling.910## Process1112### Step 1: Identify the Performance Domain1314| Domain | Symptoms | Impact |15|--------|----------|--------|16| **Startup time** | Slow cold/warm start, splash screen lingers | User drop-off, store ranking penalty |17| **UI rendering (jank)** | Dropped frames, stuttery scrolling, animation glitches | Poor perceived quality |18| **Memory** | OOM crashes, background kills, growing heap | Crashes, data loss |19| **Battery** | Excessive CPU wake, location/sensor overuse, background work | User uninstalls, OS throttling |20| **Network** | Slow data loading, excessive bandwidth, redundant requests | High latency, data costs |21| **App size** | Large download, slow install, storage warnings | Reduced installs (especially emerging markets) |2223### Step 2: Profile with Platform Tools2425#### Flutter2627| Tool | What It Measures |28|------|-----------------|29| **Flutter DevTools (Performance)** | Frame rendering times, jank detection, widget rebuilds |30| **Flutter DevTools (Memory)** | Heap snapshots, allocation tracking, leak detection |31| **Flutter DevTools (Network)** | HTTP request timing, payload sizes |32| **`flutter run --profile`** | Profile mode (release-like performance with profiling) |33| **`flutter build --analyze-size`** | APK/IPA size breakdown by package |34| **Dart Observatory** | CPU profiling, isolate performance |3536#### Android3738| Tool | What It Measures |39|------|-----------------|40| **Android Studio Profiler** | CPU, memory, network, energy — unified view |41| **Perfetto / System Trace** | System-level trace (frame rendering, binder calls, scheduling) |42| **Baseline Profiles** | Startup and runtime AOT compilation for critical paths |43| **LeakCanary** | Automatic memory leak detection |44| **Macrobenchmark** | Startup time, frame timing, scroll jank — CI-measurable |45| **R8/ProGuard reports** | Code shrinking, dead code removal, app size |46| **`adb shell dumpsys`** | Battery stats, memory info, graphics info |4748#### iOS4950| Tool | What It Measures |51|------|-----------------|52| **Xcode Instruments (Time Profiler)** | CPU usage by function, call tree analysis |53| **Xcode Instruments (Allocations)** | Memory allocations, heap growth, leaks |54| **Xcode Instruments (Core Animation)** | Off-screen rendering, blending, frame drops |55| **Xcode Instruments (Energy Log)** | CPU, network, location, Bluetooth energy impact |56| **MetricKit** | Real-world performance metrics from users in the field |57| **Xcode Organizer** | Crash reports, disk writes, launch time, hang rate |58| **App Thinning reports** | Per-device app size after slicing |5960### Step 3: Optimize by Domain6162#### Startup Time6364| Technique | Platform | Impact |65|-----------|----------|--------|66| Defer non-critical initialization | All | High |67| Use Baseline Profiles / AOT | Android / Flutter | High |68| Minimize main-thread work before first frame | All | High |69| Lazy-load feature modules | All | Medium |70| Pre-warm critical data in splash | All | Medium |71| Reduce dependency injection graph at startup | All | Medium |72| Use `--split-debug-info` and `--obfuscate` | Flutter | Medium |7374**Targets:** Cold start < 1s (simple app), < 2s (complex app). Warm start < 500ms.7576#### UI Rendering (Jank)7778| Technique | Platform | Impact |79|-----------|----------|--------|80| Use `const` constructors, minimize rebuilds | Flutter | High |81| Use `RepaintBoundary` for isolated animations | Flutter | Medium |82| Use `LazyColumn` / `LazyList` for long lists | Android / iOS | High |83| Avoid `saveLayer`, clip operations, opacity on large trees | All | Medium |84| Move computation off the main thread (Isolate, Coroutine, Task) | All | High |85| Flatten view hierarchy, avoid unnecessary nesting | All | Medium |86| Use image caching and proper image sizing | All | Medium |8788**Target:** 60 FPS (16ms per frame) or 120 FPS (8ms per frame) on high-refresh displays.8990#### Memory9192| Technique | Platform | Impact |93|-----------|----------|--------|94| Cancel subscriptions and listeners on dispose | All | High |95| Use weak references for caches | Android / iOS | Medium |96| Downsample images to display size | All | High |97| Implement pagination instead of loading full datasets | All | High |98| Avoid retaining Activity/Context references | Android | High |99| Use `@StateObject` not `@ObservedObject` for owned state | iOS | Medium |100| Profile with heap snapshots to find growth | All | High |101102**Target:** No memory growth on repeated navigation. No OOM crashes.103104#### App Size105106| Technique | Platform | Impact |107|-----------|----------|--------|108| Enable code shrinking (R8, tree shaking) | Android / Flutter | High |109| Use App Bundles (AAB) / App Thinning | Android / iOS | High |110| Compress and resize image assets | All | Medium |111| Remove unused dependencies and assets | All | Medium |112| Use vector graphics (SVG) instead of raster where possible | All | Medium |113| Split debug symbols (`--split-debug-info`) | Flutter | Medium |114| Use deferred components / on-demand resources | Flutter / Android / iOS | Medium |115116#### Network Efficiency117118| Technique | Platform | Impact |119|-----------|----------|--------|120| Implement HTTP caching (ETag, Cache-Control) | All | High |121| Use pagination and partial responses | All | High |122| Batch API requests where possible | All | Medium |123| Compress payloads (gzip) | All | Medium |124| Use protocol buffers or flatbuffers for large payloads | All | Medium |125| Prefetch data on likely user paths | All | Medium |126| Implement request deduplication | All | Medium |127128#### Battery129130| Technique | Platform | Impact |131|-----------|----------|--------|132| Batch background work with WorkManager / BGTaskScheduler | Android / iOS | High |133| Reduce location accuracy when high precision isn't needed | All | High |134| Avoid polling — use push notifications or WebSocket | All | High |135| Respect low-power mode | All | Medium |136| Minimize wake-locks and foreground services | Android | Medium |137138### Step 4: Set Up Performance Monitoring139140| Tool | Platform | Type |141|------|----------|------|142| **Firebase Performance** | All | Field metrics (startup, network, custom traces) |143| **Sentry Performance** | All | Transactions, slow frames, ANR |144| **Macrobenchmark + CI** | Android | Lab metrics in CI pipeline |145| **XCTest Performance** | iOS | Lab metrics in CI pipeline |146| **Flutter Integration Tests** | Flutter | Lab metrics in CI pipeline |147| **MetricKit** | iOS | Field metrics from real devices |148149## Output Format150151```markdown152## Performance Assessment153- **Platform:** [Flutter / Android / iOS]154- **Domain:** [Startup / Rendering / Memory / Size / Network / Battery]155- **Current Metric:** [measured value]156- **Target Metric:** [goal]157158## Root Cause Analysis159[What is causing the issue, backed by profiling data]160161## Optimization Plan162| Priority | Optimization | Expected Impact | Effort |163|----------|-------------|-----------------|--------|164| P0 | ... | ... | ... |165166## Monitoring Setup167[How to measure improvement and prevent regression]168```169170## Quality Checklist171172- [ ] Performance issue is reproduced and measured (not guessed)173- [ ] Profiling was done in release/profile mode (not debug)174- [ ] Root cause is identified before applying fixes175- [ ] Optimizations are measured before/after with numbers176- [ ] Performance regression tests are added to CI177- [ ] Field monitoring is set up for real-device metrics178179## Edge Cases180181- Debug mode performance is NOT representative — always profile in release/profile mode182- Performance varies significantly across device tiers — test on low-end devices, not just flagships183- If the app uses WebViews heavily, WebView initialization and rendering is often the bottleneck — consider prewarming or replacing with native UI184- For Flutter, platform channel calls are async and can introduce latency for rapid interactions — batch calls where possible185- Image-heavy apps should implement progressive loading and placeholder strategies