Skip to content

⚡ Performance Optimization Standards for Flutter

Table of Contents

Core Standards

Performance Requirements

  1. Always optimize for 60fps rendering performance
  2. Minimize widget rebuilds to essential updates only
  3. Use const constructors wherever possible
  4. Implement proper memory management to prevent leaks
  5. Optimize network requests for minimal data transfer
  6. Use efficient data structures for large datasets
  7. Implement proper caching strategies for frequently accessed data
  8. Profile and measure performance regularly

Performance Monitoring Rules

  1. Use Flutter DevTools for performance profiling
  2. Monitor frame rendering times and identify bottlenecks
  3. Track memory usage and detect memory leaks
  4. Measure app startup time and optimize accordingly
  5. Monitor network performance and optimize API calls
  6. Regularly audit performance with real device testing

Performance Areas

Widget Performance

  1. Use const constructors for static widgets
  2. Use RepaintBoundary for expensive paint operations
  3. Use ListView.builder for large lists instead of ListView
  4. Minimize widget tree depth and complexity
  5. Use proper widget keys when needed for efficient updates
  6. Implement proper widget composition to avoid unnecessary rebuilds
  7. Use AutomaticKeepAliveClientMixin for expensive widgets
  8. Optimize widget build methods to be as fast as possible

State Management Performance

  1. Emit states only when necessary to minimize rebuilds

Memory Management

  1. Always dispose controllers in dispose methods
  2. Cancel stream subscriptions to prevent memory leaks
  3. Use proper data structures for memory efficiency
  4. Minimize object creation in hot paths

Network Performance

  1. Implement proper request cancellation for unused requests
  2. Minimize data transfer by sending only necessary data
  3. Use proper network monitoring for performance tracking

Image and Asset Optimization

  1. Use CachedNetworkImage for network images
  2. Use proper image compression for file size optimization when needed
  3. Use proper video compression for file size optimization when needed

Common Violations

DO NOT Violate These Rules

  1. Don't use ListView or SingleChildScrollView for large lists - Use ListView.builder instead
  2. Don't forget const constructors - Always use const for static widgets
  3. Don't ignore memory leaks - Always dispose controllers and streams
  4. Don't use expensive operations in build methods - Move to separate methods
  5. Don't forget RepaintBoundary - Use for expensive paint operations
  6. Don't use unnecessary rebuilds - Implement proper state management
  7. Don't ignore performance profiling - Always profile before optimization
  8. Don't use inefficient data structures - Choose appropriate structures
  9. Don't forget image optimization - Always optimize images for mobile
  10. Don't ignore network optimization - Always implement proper caching
  11. Don't use unnecessary animations - Only animate when necessary
  12. Don't forget proper disposal - Always dispose resources properly
  13. Don't use inefficient widgets - Choose appropriate widgets for use case