| name | mobile-performance |
| description | Mobile app performance optimization, startup time, memory management, and battery efficiency |
| license | MIT |
Mobile Performance Optimization
When to Use
- Optimizing mobile app startup time
- Reducing memory footprint and preventing leaks
- Improving scroll performance and frame rates
- Optimizing battery consumption
- Reducing app bundle size
- Implementing lazy loading for mobile resources
- Optimizing image loading and caching strategies
- Improving network request efficiency on mobile
- Reducing jank and stuttering in animations
- Optimizing database queries on mobile devices
- Implementing efficient state management
- Reducing cold/warm start times
- Optimizing rendering pipeline
- Implementing efficient list/virtualization patterns
- Reducing memory allocations in hot paths
- Optimizing JavaScript execution on mobile
- Implementing efficient caching strategies
- Reducing main thread blocking operations
- Optimizing image decoding and processing
- Implementing efficient animation systems
- Reducing layout thrashing
- Optimizing touch response times
- Implementing efficient background task handling
When NOT to Use
- Desktop web performance optimization (use
performance skill instead)
- Server-side rendering optimization (use
serverless-optimization skill)
- API endpoint performance (use
api-design skill)
- Database server optimization (use
database-design skill)
- Network infrastructure optimization
- CDN configuration and optimization
- Web worker optimization for desktop
- WebGL/WebGPU performance tuning
- Progressive Web App caching strategies
- Service worker optimization
- HTTP/2 or HTTP/3 configuration
- Server push optimization
- Critical CSS generation for web
- Font loading optimization for web
- Preload/prefetch hint optimization
Prerequisites
- Understanding of mobile app architecture (React Native, Flutter, or native)
- Knowledge of mobile device constraints (memory, CPU, battery)
- Familiarity with mobile profiling tools
- Understanding of mobile network conditions (3G, 4G, 5G, offline)
- Experience with mobile-specific performance metrics
Performance Metrics
Core Mobile Metrics
| Metric | Target | Measurement Tool |
|---|
| Time to Interactive (TTI) | < 3s (4G), < 8s (3G) | Chrome DevTools, Lighthouse |
| First Contentful Paint (FCP) | < 1.8s | Chrome DevTools, Web Vitals |
| Largest Contentful Paint (LCP) | < 2.5s | Chrome DevTools, Web Vitals |
| First Input Delay (FID) | < 100ms | Chrome DevTools, Web Vitals |
| Cumulative Layout Shift (CLS) | < 0.1 | Chrome DevTools, Web Vitals |
| Total Blocking Time (TBT) | < 300ms | Chrome DevTools, Lighthouse |
| Memory Usage | < 150MB (iOS), < 200MB (Android) | Xcode Instruments, Android Profiler |
| Battery Impact | < 5% per hour | Device battery stats, battery-historian |
| Frame Rate | 60fps (target), 120fps (high refresh) | FPS counter, Performance Monitor |
| App Bundle Size | < 50MB (initial), < 100MB (total) | App Store Connect, Play Console |
Mobile-Specific Metrics
| Metric | Description | Target |
|---|
| Jank Rate | Percentage of dropped frames | < 1% |
| Touch Response Time | Time from touch to visual feedback | < 100ms |
| Scroll Smoothness | Consistency of scroll frame rate | 60fps sustained |
| Memory Leak Rate | Memory growth per navigation cycle | 0MB growth |
| Network Request Time | Average request completion time | < 500ms (cached), < 2s (network) |
| Image Load Time | Time to display optimized images | < 1s |
| Animation Frame Budget | Time available per frame | 16.67ms (60fps) |
Startup Time Optimization
Cold Start Optimization
class App extends Component {
componentDidMount() {
this.loadUserData();
this.initializeAnalytics();
this.fetchNotifications();
this.syncLocalDatabase();
this.preloadImages();
}
}
class App extends Component {
componentDidMount() {
this.showSplashScreen();
Promise.all([
this.initializeCoreServices(),
this.loadUserPreferences(),
]).then(() => {
this.navigateToMainScreen();
this.initializeAnalytics();
this.fetchNotifications();
this.syncLocalDatabase();
});
}
}
React Native Startup Optimization
import React, { lazy, Suspense } from 'react';
import { ActivityIndicator, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
const Dashboard = lazy(() => import('./screens/Dashboard'));
const Settings = lazy(() => import('./screens/Settings'));
const Profile = lazy(() => import('./screens/Profile'));
const LazyScreen = ({ screen }) => (
<Suspense
fallback={
<View style={styles.loadingContainer}>
<ActivityIndicator size="large" />
</View>
}
>
{screen}
</Suspense>
);
export default function App() {
return (
<NavigationContainer>
{/* Heavy screens are only loaded when navigated to */}
<Stack.Screen
name="Dashboard"
component={() => <LazyScreen screen={<Dashboard />} />}
/>
<Stack.Screen
name="Settings"
component={() => <LazyScreen screen={<Settings />} />}
/>
<Stack.Screen
name="Profile"
component={() => <LazyScreen screen={<Profile />} />}
/>
</NavigationContainer>
);
}
Flutter Startup Optimization
// main.dart - Optimized startup
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Pre-warm cache in background
DefaultCacheManager().getFileFromCache('banner.jpg').then((_) {
// Cache warmed, navigate to main app
});
// Initialize services without blocking
unawaited(initializeAnalytics());
unawaited(syncLocalDatabase());
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isLoading = true;
@override
void initState() {
super.initState();
// Show splash, load critical data
loadCriticalData().then((_) {
setState(() {
_isLoading = false;
});
});
}
@override
Widget build(BuildContext context) {
if (_isLoading) {
return const SplashScreen();
}
return const MainApp();
}
}
Memory Optimization
Prevent Memory Leaks
class Component extends React.Component {
componentDidMount() {
EventEmitter.on('data', this.handleData);
setInterval(this.pollData, 5000);
}
render() {
return <View />;
}
}
class Component extends React.Component {
componentDidMount() {
EventEmitter.on('data', this.handleData);
this.intervalId = setInterval(this.pollData, 5000);
}
componentWillUnmount() {
EventEmitter.off('data', this.handleData);
clearInterval(this.intervalId);
}
render() {
return <View />;
}
}
Image Memory Management
import FastImage from 'react-native-fast-image';
import {Image} from 'react-native';
const IMAGE_SIZES = {
thumbnail: {width: 100, height: 100},
medium: {width: 400, height: 300},
large: {width: 800, height: 600},
};
const OptimizedImage = ({uri, size = 'medium'}) => (
<FastImage
source={{
uri,
priority: FastImage.priority.normal,
// Cache control
cache: FastImage.cacheControl.cacheOnly,
}}
style={{
width: IMAGE_SIZES[size].width,
height: IMAGE_SIZES[size].height,
}}
resizeMode={FastImage.resizeMode.cover}
/>
);
import 'package:cached_network_image/cached_network_image.dart';
Widget optimizedImage(String url) {
return CachedNetworkImage(
imageUrl: url,
memCacheWidth: 400,
memCacheHeight: 300,
fadeInDuration: Duration(milliseconds: 300),
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
);
}
Scroll Performance
Virtualized Lists
import {FlatList} from 'react-native';
const OptimizedList = ({items}) => (
<FlatList
data={items}
renderItem={RenderItem}
// Key optimizations
keyExtractor={item => item.id}
initialNumToRender={10} // Render first 10 items
maxToRenderPerBatch={5} // Batch size for subsequent renders
windowSize={5} // Number of screens to render
removeClippedSubviews={true} // Remove off-screen views (Android)
// Performance optimizations
getItemLayout={(data, index) => ({
length: ITEM_HEIGHT,
offset: ITEM_HEIGHT * index,
index,
})}
// Remove layout calculation
onEndReachedThreshold={0.5} // Load more at 50% from end
onEndReached={() => loadMore()}
// Memoize render
renderItem={({item}) => <MemoizedItem item={item}/>}
/>
);
import 'package:flutter_slidable/flutter_slidable.dart';
Widget optimizedList(List<Item> items) {
return ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
return ListTile(
key: ValueKey(item.id),
title: Text(item.title),
subtitle: Text(item.subtitle),
leading: CircleAvatar(child: Text(item.initial)),
);
},
cacheExtent: 500.0,
addAutomaticKeepAlives: true,
addRepaintBoundaries: true,
);
}
Battery Optimization
Reduce Background Activity
import { AppState } from 'react-native';
class BatteryEfficientComponent extends Component {
state = { appState: AppState.currentState };
componentDidMount() {
this.appStateSubscription = AppState.addEventListener(
'change',
this.handleAppStateChange
);
if (this.state.appState === 'active') {
this.startPolling();
}
}
handleAppStateChange = (nextAppState) => {
if (this.state.appState === 'active' && nextAppState === 'inactive') {
this.stopPolling();
} else if (nextAppState === 'active') {
this.startPolling();
}
this.setState({ appState: nextAppState });
};
componentWillUnmount() {
this.appStateSubscription?.remove();
this.stopPolling();
}
}
Bundle Size Optimization
Code Splitting
import React, { lazy, Suspense } from 'react';
const ChatFeature = lazy(() => import('./features/Chat'));
const PaymentFeature = lazy(() => import('./features/Payment'));
const SettingsFeature = lazy(() => import('./features/Settings'));
const Dashboard = lazy(() => import('./screens/Dashboard'));
const Profile = lazy(() => import('./screens/Profile'));
const PlatformSpecific = lazy(() =>
Platform.OS === 'ios'
? import('./components/IOSComponent')
: import('./components/AndroidComponent')
);
Tree Shaking
import _ from 'lodash';
_.debounce(() => {});
import debounce from 'lodash/debounce';
Profiling Tools
React Native
Flutter
| Tool | Purpose | URL |
|---|
| Flutter DevTools | Performance, memory, network | https://docs.flutter.dev/tools/devtools |
| Timeline | Frame rendering analysis | Built into Flutter |
| Memory View | Heap analysis | Flutter DevTools |
| Network View | Request monitoring | Flutter DevTools |
Production Checklist
References