--- name: capacitor-performance description: Diagnoses and fixes performance problems specific to Capacitor apps - slow cold start or long splash, white screen after camera/backgrounding (WKWebView "WebView process terminated" reload, Android onRenderProcessGone), large base64 payloads over the native bridge (Camera, Filesystem.readFile, CapacitorHttp), jank in the WebView, memory growth from unremoved plugin listeners, oversized Preferences storage, slow Android WebView versions, and debug logging left on in release. Covers profiling with Safari Web Inspector, chrome://inspect, Xcode Instruments, Android Studio Profiler, and adb timing commands. Do not use for crash/stack-trace debugging (use debugging-capacitor or capacitor-native-observability), device log capture (use ios-android-logs), offline data architecture (use capacitor-offline-first / sqlite-to-fast-sql), splash configuration details (use capacitor-splash-screen), or generic web performance unrelated to Capacitor. --- # Capacitor Performance Find the bottleneck first (WebView JS, bridge, native, or network), then fix the specific cause. Generic web advice (code splitting, image compression, virtual lists) still applies; this skill focuses on what is different inside Capacitor. ## When to Use TRIGGER when: - Cold start is slow, splash stays long, or the first screen is blank for seconds. - App "restarts" or shows a white screen after taking a photo, opening a big file, or returning from background. - Native calls feel slow, especially with images, files, or large HTTP responses. - Scrolling/animations jank only on device (often older Android WebView). - Memory grows over time; listeners pile up. Do not use: - Crashes, native stack traces -> `debugging-capacitor`, `capacitor-native-observability`. - Getting logs off a device -> `ios-android-logs`. - Offline storage design / SQLite migration -> `capacitor-offline-first`, `sqlite-to-fast-sql`. - Splash screen setup -> `capacitor-splash-screen`; keyboard resize jank -> `capacitor-keyboard`. - OTA bundle size and delta updates -> `capgo-live-updates`. ## Procedure 1. **Reproduce on a real device in a release-like build.** Debug builds log every bridge call and disable optimizations; simulators hide memory and GPU limits. 2. **Classify** with the profiling table below: JS main thread busy, bridge payloads large, native thread busy, or waiting on network. 3. **Check the traps** list. Most Capacitor-specific regressions are one of these. 4. **Fix one thing, measure again** with the same command/trace. Report before/after numbers to the user. ## Profiling Quick Reference | Question | Tool | |---|---| | JS long tasks, layout, paint (iOS) | Safari > Develop > device > app > Timelines. Requires `ios.webContentsDebuggingEnabled: true` for release builds (debug builds are inspectable by default on iOS 16.4+). | | JS long tasks, memory heap (Android) | `chrome://inspect` > Performance / Memory. | | Native CPU, allocations, leaks (iOS) | Xcode > Product > Profile > Time Profiler / Allocations / Leaks; field data in Xcode Organizer > Metrics. | | Native CPU/memory (Android) | Android Studio > Profiler. | | Android cold start time | `adb shell am force-stop && adb shell am start -W -n /.MainActivity` (read `TotalTime`). | | Android frame stats | `adb shell dumpsys gfxinfo ` (janky frames %). | | Android WebView version | `adb shell dumpsys webviewupdate` (current provider and version). | Details and recipes: `references/profiling.md`. ## Capacitor-Specific Traps 1. **Base64 over the bridge.** Every plugin call/response is JSON-serialized across the bridge. Multi-MB base64 strings stall both threads and can kill the WebView process. - Camera (`@capacitor/camera` 8.1+ API): use `takePhoto` / `chooseFromGallery` and display `result.webPath`; set `targetWidth`/`targetHeight`/`quality`. Avoid reading full-resolution base64 unless uploading. The older `getPhoto` / `pickImages` are deprecated. - Files: pass paths, use `Capacitor.convertFileSrc(uri)` for `/