Skip to main content

avoid-slow-collection-methods

added in: 1.15.0
Pro+

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.

Example

❌ Bad:

void fn() {
const iterable = [null, 2, 3, 4, 5, 6, 7, 8, 9];

iterable.whereNotNull(); // LINT: Avoid calling slow sync* methods. Try using a different method instead.
}

✅ Good:

void fn() {
const iterable = [null, 2, 3, 4, 5, 6, 7, 8, 9];

iterable.whereType<int>(); // Correct, not a 'sync*' method
}

Additional Resources