Performance Optimization
Measure first with DevTools (CPU profiler, memory, timeline) and benchmark_harness.
Language level: Use const constructors and literals (canonicalized, zero allocation, and skipped rebuilds in Flutter).
Prefer final. Avoid dynamic (slower dynamic dispatch, lost optimizations).
Use StringBuffer for string building. Use typed data (Uint8List, Float64List) for numeric arrays.
Avoid unnecessary allocations in hot loops. Reuse objects. Use lazy Iterables wisely (don't re-iterate expensive chains: toList() once).
Use records/extension types for zero- or low-cost abstractions.
Async: avoid sequential awaits that could run in parallel. Don't block the event loop: move CPU-heavy work to Isolate.run. Stream large data instead of loading it all.
Compilation: use AOT (dart compile exe, Flutter release mode) for production. Use tree shaking. Minify JS with -O2/-O4 for the web. Use Wasm for compute-heavy web apps.
Flutter specifics: minimize rebuilds (split widgets, const, selectors), use ListView.builder, avoid expensive build methods, cache images, use RepaintBoundary, avoid Opacity/saveLayer overuse, keep frames under 16 ms (8 ms on 120 Hz screens), and use Impeller.
Memory: cancel StreamSubscriptions and timers, dispose controllers, avoid holding large objects in closures/static fields, and use DevTools' memory leak tracking.