Performance Optimization
Component Rendering
Minimize unnecessary re-renders using memoization:- Wrap components with
React.memoto prevent re-renders when props don’t change - Use
useMemofor expensive calculations - Use
useCallbackfor callback functions passed as props - Avoid creating functions or objects inside render methods
- Split contexts by update frequency
List Performance
Optimize FlatList and SectionList for smooth scrolling:- Always provide a stable
keyExtractor(avoid using index) - Set
initialNumToRenderbased on screen size (typically 10-20) - Enable
removeClippedSubviewsfor long lists (test on Android) - Use
getItemLayoutfor fixed-height items - Set appropriate
windowSize(5-21, default 21) - Memoize list item components
- Avoid inline styles or functions in
renderItem
Memory Management
Image Optimization
Images are often the largest memory consumers:- Use
expo-imageinstead of defaultImagecomponent - Resize images to display dimensions before serving
- Use WebP format for photographs
- Implement lazy loading for off-screen images
- Set cache limits for user-generated content
- Use thumbnails in lists, full resolution only when needed
- Implement progressive loading with blurhash placeholders
Memory Leak Prevention
Always clean up resources:- ✅ Clean up timers (setTimeout, setInterval)
- ✅ Remove event listeners on unmount
- ✅ Cancel pending async operations
- ✅ Unsubscribe from stores/observables
- ✅ Stop animations when components unmount
- ✅ Clear references to unmounted screens
- ✅ Use refs for non-rendering values
Native-Like Experience
Navigation
Use React Navigation with native stack:- Use native stack navigator for best performance
- Enable gesture handling (swipe-back on iOS)
- Match platform transition animations
- Minimize navigation stack depth
- Use modal presentations for secondary flows
Touch and Gestures
Implement responsive touch feedback:- Use
PressableoverTouchableOpacityfor better performance - Minimum touch target size: 44x44 points
- Set appropriate
hitSlopfor small targets - Provide immediate visual feedback
- Use haptic feedback for important actions
- Use React Native Gesture Handler for complex gestures
Platform-Specific Patterns
Respect platform conventions:Code Architecture
Component Organization
Structure components for maintainability:- Separate presentational and container components
- Keep components focused and small (under 200 lines)
- Use custom hooks for reusable logic
- Implement proper error boundaries
- Use TypeScript for type safety
State Management
Choose appropriate state management:- Keep component state local when possible
- Use Context for shared app state
- Use Zustand/Jotai for complex global state
- Implement proper selectors to prevent re-renders
- Avoid storing derived data in state
Custom Hooks
Encapsulate reusable logic:Build Optimization
Bundle Size Management
Minimize bundle size:Asset Optimization
Optimize all assets:- Compress images (ImageOptim, TinyPNG)
- Generate @1x, @2x, @3x resolutions
- Use SVG for icons (react-native-svg)
- Optimize SVG files (SVGO)
- Configure asset compression in app.json
Runtime Performance
Startup Time Optimization
Minimize app launch time:- Keep splash screen visible during initialization
- Load only critical resources on startup
- Defer non-critical tasks (analytics, etc.)
- Use lazy loading for non-initial screens
- Minimize work in app entry point
JavaScript Thread Performance
Keep JS thread responsive:Native Thread Utilization
Move animations to native thread:- Use
react-native-reanimatedfor complex animations - Enable
useNativeDriver: truewhen possible - Animate transform and opacity (GPU-accelerated)
- Avoid animating layout properties (width, height, etc.)
- Keep animations at 60fps
Monitoring and Testing
Performance Monitoring
Monitor app performance:Testing on Real Devices
Always test on actual devices:- ✅ Test on low-end and high-end devices
- ✅ Test on different screen sizes
- ✅ Monitor memory usage
- ✅ Check frame rate (should be 60fps)
- ✅ Test with poor network conditions
- ✅ Test with low battery
Summary
Performance Checklist
- ✅ Memoize components and callbacks
- ✅ Optimize FlatList configuration
- ✅ Use expo-image for images
- ✅ Clean up resources in useEffect
- ✅ Use native stack navigator
- ✅ Implement proper touch targets (44x44)
- ✅ Minimize bundle size
- ✅ Defer non-critical startup tasks
- ✅ Use native driver for animations
- ✅ Test on real devices
Common Pitfalls to Avoid
- ❌ Creating functions/objects in render
- ❌ Not providing stable keys to FlatList
- ❌ Using large unoptimized images
- ❌ Forgetting to clean up subscriptions
- ❌ Animating layout properties
- ❌ Doing heavy work on JS thread
- ❌ Testing only on high-end devices
Resources
Building performant mobile apps requires attention to detail and continuous profiling. Follow these best practices to create native-like experiences that delight users! 🚀
