| name | capacitor-performance |
| description | Performance optimization guide for Capacitor apps covering bundle size, rendering, memory, native bridge, and profiling. Use this skill when users need to optimize their app performance. |
Performance Optimization for Capacitor
Make your Capacitor apps fast and responsive.
When to Use This Skill
- User has slow app
- User wants to optimize
- User has memory issues
- User needs profiling
- User has janky animations
Quick Wins
1. Lazy Load Plugins
import { Camera } from '@capacitor/camera';
import { Filesystem } from '@capacitor/filesystem';
import { Geolocation } from '@capacitor/geolocation';
async function takePhoto() {
const { Camera } = await import('@capacitor/camera');
return Camera.getPhoto({ quality: 90 });
}
2. Reduce Bundle Size
npx vite-bundle-visualizer
import { specific } from 'large-library'; // Good
import * as everything from 'large-library'; // Bad
3. Optimize Images
const photo = await Camera.getPhoto({
quality: 80,
width: 1024,
resultType: CameraResultType.Uri,
});
<img loading="lazy" src={url} />
4. Minimize Bridge Calls
for (const item of items) {
await Storage.set({ key: item.id, value: item.data });
}
await Storage.set({
key: 'items',
value: JSON.stringify(items),
});
Rendering Performance
Use CSS Transforms
.animated {
transform: translateX(100px);
will-change: transform;
}
.animated {
left: 100px;
}
Virtual Scrolling
import { VirtualScroller } from 'your-framework';
<VirtualScroller
items={items}
itemHeight={60}
renderItem={(item) => <ListItem item={item} />}
/>
Debounce Events
import { debounce } from 'lodash-es';
const handleScroll = debounce((e) => {
}, 16);
Memory Management
Cleanup Listeners
import { App } from '@capacitor/app';
const handle = await App.addListener('appStateChange', callback);
onUnmount(() => {
handle.remove();
});
Avoid Memory Leaks
let largeData = await fetchLargeData();
processData(largeData);
largeData = null;
Profiling
Chrome DevTools
- Connect via chrome://inspect
- Performance tab > Record
- Analyze flame chart
Xcode Instruments
- Product > Profile
- Choose Time Profiler
- Analyze hot paths
Android Profiler
- View > Tool Windows > Profiler
- Select CPU/Memory/Network
- Record and analyze
Metrics to Track
| Metric | Target |
|---|
| First Paint | < 1s |
| Time to Interactive | < 3s |
| Frame Rate | 60fps |
| Memory | Stable, no growth |
| Bundle Size | < 500KB gzipped |
Resources