Slow asynchronous dart:io call with a faster synchronous form

ID

dart.performance.avoid_slow_async_io

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Io

Language

Dart

Description

Reports the dart:io metadata calls whose asynchronous form is slower than its synchronous counterpart - exists, stat, lastModified on File, Directory and Link, and the FileSystemEntity.isDirectory, isFile, isLink and type statics.

Rationale

These operations do not block: they read an inode the operating system answers from cache, and the work is over long before a thread would have yielded. Running them asynchronously therefore buys nothing and costs the overhead of the async machinery - marshalling the request to the I/O thread pool, allocating the Future, and scheduling the continuation - which measurably exceeds the call itself and forces every caller up the chain to become async as well. The synchronous form does the same work in one step.

The following code illustrates the pattern detected by this rule:

class Assets {
  Future<bool> present(String path) async {
    // FLAGGED: Slow asynchronous dart:io call with a faster synchronous form
    return await File(path).exists();
  }
}

Remediation

Call the Sync variant - existsSync(), statSync(), lastModifiedSync(), isDirectorySync(), isFileSync(), isLinkSync(), typeSync() - and drop the await. Keep the asynchronous form for the calls that really do wait, such as reading or writing file contents.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved