Optimizing FlatList Performance
Learn how to optimizeFlatList for smooth 60 FPS scrolling, even with large datasets. FlatList is React Native’s high-performance list component that virtualizes content.
How FlatList Works
FlatList uses VirtualizedList under the hood to:- Render only visible items: Items outside viewport are unmounted
- Recycle components: Reuse components as you scroll
- Batch updates: Group multiple updates for efficiency
- Windowing: Keep a buffer of items above and below viewport
Basic FlatList Setup
Essential Optimizations
1. Implement getItemLayout
Prevent expensive layout calculations by providing item dimensions:- No layout measurements needed
- Instant scroll position calculation
- Smooth
scrollToIndexbehavior
2. Use keyExtractor Correctly
Provide stable, unique keys:3. Optimize renderItem with React.memo
Prevent unnecessary re-renders:4. Configure Window Size
Control how many items to keep mounted:initialNumToRender: First batch size (default: 10)maxToRenderPerBatch: Items per subsequent batch (default: 10)windowSize: Screen lengths to keep mounted (default: 21)- Lower values = less memory, more blank content during fast scrolling
5. Remove Clipped Subviews
Unmount off-screen components (Android primarily):- Reduced memory usage
- Better performance on Android
- May cause issues with animations
- Can have bugs with complex layouts
Advanced Optimizations
Avoid Anonymous Functions
Optimize Images
Use ListEmptyComponent
Implement Pull to Refresh
Infinite Scroll
Measuring Performance
Monitor Render Times
Track Scroll Performance
Common Performance Issues
Issue 1: Slow Scrolling
Symptoms: Choppy scrolling, frame drops Solutions:- Implement
getItemLayout - Reduce
windowSize - Optimize
renderItemwithReact.memo - Avoid heavy computations in render
Issue 2: Blank Content While Scrolling
Symptoms: White space during fast scrolling Solutions:- Increase
initialNumToRender - Increase
maxToRenderPerBatch - Increase
windowSize
Issue 3: Memory Issues
Symptoms: App crashes with large lists Solutions:- Decrease
windowSize - Enable
removeClippedSubviews - Optimize images (compress, use thumbnails)
- Implement pagination
Issue 4: Incorrect Item Updates
Symptoms: Wrong items update or display Solutions:- Use stable
keyExtractor - Implement proper
extraDataprop
FlatList vs SectionList
UseSectionList for grouped data:
Testing Performance
Create Test Data
Benchmark Configurations
Best Practices Checklist
- Use stable
keyExtractor(not index) - Implement
getItemLayoutfor fixed-height items - Wrap items with
React.memo - Use
useCallbackfor event handlers - Configure
initialNumToRender,maxToRenderPerBatch,windowSize - Enable
removeClippedSubviewson Android - Optimize images (size, caching, loading)
- Avoid anonymous functions in props
- Profile and measure performance
- Test on low-end devices
Next Steps
- Learn about profiling React Native apps
- Implement RAM bundles and inline requires
- Review performance overview
- Configure Android setup for production