avoid-slow-collection-methods
added in: 1.15.0
Warns when an invocation is a slow sync*
invocation.
Using sync*
invocations can result in a ~2 times slower code compared to other approaches.
Additionally, this rule highlights .expand()
usages as replacing them with a spread gives ~3 times performance difference. See the second link for more details.
Additional resources:
- https://github.com/dart-lang/sdk/issues/51806
- https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/lib/src/utilities/extensions/collection.dart#L37
Example
❌ Bad:
void fn() {
const iterable = [null, 2, 3, 4, 5, 6, 7, 8, 9];
iterable.whereNotNull(); // LINT
}
✅ Good:
void fn() {
const iterable = [null, 2, 3, 4, 5, 6, 7, 8, 9];
iterable.whereType<int>();
}