dartr

Preview · v0.1.0-preview.10 · Dart SDK 3.13.3

dartr

A Rust port of the Dart analyzer (Dart SDK 3.13.3) with analyze, format, fix and language-server.

Install
$ brew install orestesgaolin/tap/dartr
Hand-drawn comic. A speech bubble says "rewrite dart analyzer in rust". The computer answers ">rewrites dart analyzer in rust". The person at the desk says "oh my god".

Benchmarks

Measured on a single machine (Apple M5 Pro, 15 cores, 48 GB RAM) against Dart SDK 3.13.3. Files are analyzed in parallel on all cores. Dart caches results on disk (~/.dartServer); dartr does not yet.

dartr analyze

Wall time in seconds, lower is better. Measured while other builds ran (load average 5 to 11).

  • dart analyze, warm disk cache
  • dart analyze, empty cache
  • dartr analyze, cold (no cache)
Flutter application1,559,637 lines · plugins · mean of 3 runs
Flutter packages/flutter1,309,663 lines · mean of 3 runs
analyzer 9.0.0 (pub)909,249 lines · mean of 3 runs
flutter_tools455,099 lines · mean of 3 runs
Peak memorymedian of 3 runs · peak RSS
projectDart linesdart, warm cachedart, empty cachedartrpeak RSS (dart / dartr)
Flutter application (pub workspace, analyzer plugins)1,559,63762.7 s81.7 s22 s5,955 MB / 5,651 MB
Flutter packages/flutter1,309,6636 s19.8 s1.75 s915 MB / 1,497 MB
analyzer 9.0.0 (pub)909,2493.1 s8.7 s0.84 s490 MB / 790 MB
flutter_tools455,0991.6 s12.1 s0.87 s492 MB / 918 MB

dartr language-server

Measured on the same machine (load average 5 to 7) with bench/lsp_bench.py. Memory is RSS after startup.

  • dart language-server, cold (empty cache)
  • dart language-server, warm cache
  • dartr language-server (no cache)
Startupdart cold: 1 run · dart warm, dartr: 2 runs · split scale
Completion after .median of 20 positions
References (first request)1 request per project · split scale
Memory after startupprocess-tree RSS
projectserverstartup cold / warmhovercompletion . / stmtreferences repeat / firstmemory
flutter_toolsdart8.5 s / 1.6 s0.1 ms2.7 / 30 ms45 ms / 75 ms546 MB
dartr1.3–2.2 s0.0 ms1.1 / 24 ms17 ms / 181 ms962 MB
analyzer 9.0.0dart9.0 s / 4.7 s0.1 ms2.1 / 19 ms13 ms / 16 ms612 MB
dartr1.0–1.5 s0.0 ms0.7 / 14 ms2 ms / 34 ms910 MB
Flutter packages/flutterdart20.9 s / 4.0 s0.1 ms2.7 / 45 ms170 ms / 2.9 s823 MB
dartr3.6–4.2 s0.1 ms1.5 / 32 ms58 ms / 1.2 s1,652 MB
Flutter applicationdart77 s / 87 s0.2 ms5.8 / 57 ms90 ms / 2.5 s6,773 MB
dartr26 s*0.1 ms2.3 / 43 ms13 ms / 2.0 s5,270 MB

* 70 s on the first start after installing a new dartr version (the analyzer plugin is prepared once).

Method: hyperfine -i -N -w 1 -r 3 via bench/compare.sh, /usr/bin/time -l via bench/memory.sh, and bench/lsp_bench.py; see docs/BENCHMARKS.md for more charts and full results.

Parity

dartr analyze reports the same diagnostics as dart analyze (3.13.3) on Flutter (packages/flutter), flutter_tools, analyzer 9.0.0, a 1.56 million line Flutter application (with analyzer plugins) and 671 real packages from the pub cache and the Flutter SDK. dartr format matches dart format on the dart_style tests and 220 pub packages, dartr fix matches dart fix on 65 pub packages with 85 fixable lints enabled, and dartr language-server registers every capability of dart language-server (plus all 59 requests and 22 notifications of --protocol=analyzer).

Correctness is checked with differential tests against the Dart SDK 3.13.3 tools on the SDK test suite and package corpora; see the README.

Differences

  • Memory: 1.5 to 2 times Dart's on packages, slightly lower on the full application (see the memory charts).
  • No disk cache: dartr analyzes from source on every run, so a warm dart language-server can start faster on packages (1.6 s vs 1.3–2.2 s on flutter_tools, 4.0 s vs 3.6–4.2 s on Flutter).
  • Remaining gaps: dartr fix does not include pubspec.yaml missing_dependency fixes yet. flutter analyze and IntelliJ invoke <sdk>/bin/dart language-server directly and have no setting for another binary.
  • Platforms and SDK requirement: macOS arm64 and Linux x86_64 only. Requires a Dart or Flutter SDK (3.13.3) on PATH to read the dart: libraries.

Editor setup

  • VS Code (Dart-Code): set "dart.analyzerPath" to /opt/homebrew/opt/dartr/libexec/dartr_shim.dart (installed by Homebrew), then reload the window.
  • Neovim, Helix, Zed, Emacs, Sublime: run dartr language-server as the Dart language server.
  • Back to the Dart server: remove "dart.analyzerPath" and reload the window.
  • Details: docs/editor-setup.md.