Identify and remove unnecessary operations that impact performance, including redundant checks, duplicate calculations, unnecessary allocations, and redundant code paths. This is especially critical in hot paths like widget rebuilds, message handling, and frequently called methods.
Examples of redundant operations to avoid:
// Better - let parseFloat handle it styleProperty = parsed;
2. **Unnecessary allocations in hot paths**: Avoid creating new objects on every call, especially in message handlers or frequent operations:
```dart
// Avoid - allocates list on every message
final List<Handler> handlers = List<Handler>.from(_messageHandlers);
// Better - use debug assertions to prevent modification during iteration
// Better - move to didChangeDependencies
4. **Duplicate calculations**: Restructure code to avoid computing the same value multiple times:
```dart
// Avoid - computes lerpValue twice
double lerpValue = ui.lerpDouble(widget.min, widget.max, value)!;
if (widget.divisions != null) {
lerpValue = (lerpValue * widget.divisions!).round() / widget.divisions!;
}
// Better - use if-else with single computation per path
Enter the URL of a public GitHub repository