一键导入
mobile-performance
Mobile app performance optimization, startup time, memory management, and battery efficiency
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Mobile app performance optimization, startup time, memory management, and battery efficiency
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when implementing accessible web content following WCAG 2.1 AA standards, semantic HTML, ARIA attributes, keyboard navigation, and screen reader support. Includes accessibility testing, compliance verification, and inclusive design practices. Based on CPACC certification and W3C WCAG standards.
Use when coordinating multiple agents for complex tasks, managing agent teams, or delegating work across specialized agents. Includes patterns for agent communication, task delegation, and team coordination following Qwen Orchestrator conventions. Based on agent collaboration patterns and distributed systems best practices.
Use when managing agile projects, facilitating Scrum ceremonies, conducting backlog grooming, sprint planning, velocity tracking, and implementing Kanban workflows. Includes agile metrics, team dynamics, and agile transformation guidance. Based on CSM, CSP, PRINCE2 certifications.
Use when verifying AI-generated content, validating claims, checking source credibility, implementing evidence-based reasoning, and preventing AI hallucinations. Includes source verification, fact-checking, and validation frameworks. Based on information verification best practices and AI safety guidelines.
Anti-pattern detection and prevention skill. Catches hardcoded data, non-functional UI elements, placeholder code, N+1 queries, and other common development anti-patterns before they ship.
RESTful and GraphQL API design skill with endpoint patterns, request/response schemas, versioning, pagination, filtering, error handling, and API documentation.
| name | mobile-performance |
| description | Mobile app performance optimization, startup time, memory management, and battery efficiency |
| license | MIT |
performance skill instead)serverless-optimization skill)api-design skill)database-design skill)| 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 |
| 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) |
// ❌ BAD: Heavy operations during startup
class App extends Component {
componentDidMount() {
// All these block startup
this.loadUserData();
this.initializeAnalytics();
this.fetchNotifications();
this.syncLocalDatabase();
this.preloadImages();
}
}
// ✅ GOOD: Prioritized, async startup
class App extends Component {
componentDidMount() {
// Phase 1: Show splash screen immediately
this.showSplashScreen();
// Phase 2: Critical initialization (parallel)
Promise.all([
this.initializeCoreServices(),
this.loadUserPreferences(),
]).then(() => {
// Phase 3: Navigate to main screen
this.navigateToMainScreen();
// Phase 4: Background tasks (non-blocking)
this.initializeAnalytics();
this.fetchNotifications();
this.syncLocalDatabase();
});
}
}
// App.js - Optimized startup
import React, { lazy, Suspense } from 'react';
import { ActivityIndicator, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
// Lazy load heavy screens
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>
);
}
// 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();
}
}
// ❌ BAD: Memory leak from event listeners
class Component extends React.Component {
componentDidMount() {
EventEmitter.on('data', this.handleData);
setInterval(this.pollData, 5000);
}
// Missing cleanup!
render() {
return <View />;
}
}
// ✅ GOOD: Proper cleanup
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 />;
}
}
// React Native - Image optimization
import FastImage from 'react-native-fast-image';
import {Image} from 'react-native';
// Predefine image sizes
const IMAGE_SIZES = {
thumbnail: {width: 100, height: 100},
medium: {width: 400, height: 300},
large: {width: 800, height: 600},
};
// Use FastImage with caching
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}
/>
);
// Flutter - Image optimization
import 'package:cached_network_image/cached_network_image.dart';
Widget optimizedImage(String url) {
return CachedNetworkImage(
imageUrl: url,
// Memory cache settings
memCacheWidth: 400, // Constrain memory cache
memCacheHeight: 300,
// Disk cache
fadeInDuration: Duration(milliseconds: 300),
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
);
}
// React Native - FlatList optimization
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}/>}
/>
);
// Flutter - ListView optimization
import 'package:flutter_slidable/flutter_slidable.dart';
Widget optimizedList(List<Item> items) {
return ListView.builder(
// Pre-calculate item count
itemCount: items.length,
// Use builder pattern
itemBuilder: (context, index) {
final item = items[index];
return ListTile(
key: ValueKey(item.id), // Stable key
title: Text(item.title),
subtitle: Text(item.subtitle),
leading: CircleAvatar(child: Text(item.initial)),
);
},
// Optimize scrolling
cacheExtent: 500.0, // Pre-render 500px ahead
addAutomaticKeepAlives: true, // Keep item state
addRepaintBoundaries: true, // Isolate repaints
);
}
// React Native - Battery-efficient polling
import { AppState } from 'react-native';
class BatteryEfficientComponent extends Component {
state = { appState: AppState.currentState };
componentDidMount() {
this.appStateSubscription = AppState.addEventListener(
'change',
this.handleAppStateChange
);
// Only poll when app is in foreground
if (this.state.appState === 'active') {
this.startPolling();
}
}
handleAppStateChange = (nextAppState) => {
if (this.state.appState === 'active' && nextAppState === 'inactive') {
this.stopPolling(); // App went to background
} else if (nextAppState === 'active') {
this.startPolling(); // App came to foreground
}
this.setState({ appState: nextAppState });
};
componentWillUnmount() {
this.appStateSubscription?.remove();
this.stopPolling();
}
}
// React Native - Dynamic imports
import React, { lazy, Suspense } from 'react';
// Split by feature
const ChatFeature = lazy(() => import('./features/Chat'));
const PaymentFeature = lazy(() => import('./features/Payment'));
const SettingsFeature = lazy(() => import('./features/Settings'));
// Split by route
const Dashboard = lazy(() => import('./screens/Dashboard'));
const Profile = lazy(() => import('./screens/Profile'));
// Split by platform
const PlatformSpecific = lazy(() =>
Platform.OS === 'ios'
? import('./components/IOSComponent')
: import('./components/AndroidComponent')
);
// ❌ BAD: Import entire library
import _ from 'lodash';
_.debounce(() => {});
// ✅ GOOD: Import only what you need
import debounce from 'lodash/debounce';
| Tool | Purpose | URL |
|---|---|---|
| React DevTools | Component hierarchy, render timing | https://facebook.github.io/react-native/react-devtools |
| Hermes Profiler | JavaScript execution profiling | Built into React Native |
| Flipper | Network, layout, plugin debugging | https://fbflipper.com |
| Android Profiler | Memory, CPU, network | Android Studio |
| Instruments | Memory leaks, energy impact | Xcode |
| 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 |