dartr

Preview · v0.1.0-preview.11 · 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. dart analyze runs the analysis on one core (one isolate, plus the VM's own helper threads); dartr analyzes libraries in parallel on all cores, which gives most of its lead on a cold run. Dart caches results on disk (~/.dartServer); dartr has an optional disk cache (--cache / DARTR_CACHE_DIR, off by default).

dartr analyze

Wall time in seconds, lower is better. Measured at load average 4 to 6.

  • dart analyze, warm disk cache
  • dart analyze, empty cache
  • dartr analyze (cold or warm --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 cachedartrdartr, warm cachepeak RSS (dart / dartr / warm cache)
Flutter application (pub workspace, analyzer plugins)1,559,63778.4 s (52.2–107.1 s)77.6 s18.4 s16.0 s*3,989 MB / 2,332 MB / 2,258 MB*
Flutter packages/flutter1,309,6637.8 s20.3 s1.82 s0.21 s907 MB / 855 MB / 122 MB
analyzer 9.0.0 (pub)909,2492.3 s9.7 s0.88 s0.21 s566 MB / 606 MB / 117 MB
flutter_tools455,0992.4 s8.6 s0.87 s0.25 s378 MB / 543 MB / 103 MB

* 1.32 s and 274 MB without the analyzer plugin (which runs in a Dart subprocess).

dartr language-server

Measured on the same machine (load average 4 to 6, with a short spike to 28 at the start of the Flutter run; dartr startup on Flutter and analyzer 9.0.0 from a separate run at load average 3) 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_toolsdart9.3 s / 1.4 s0.1 ms2.8 / 26 ms42 ms / 57 ms266 MB
dartr0.9–3.7 s0.0 ms1.5 / 25 ms1.6 ms / 288 ms544 MB
analyzer 9.0.0dart8.1 s / 1.9 s0.1 ms2.1 / 23 ms20 ms / 36 ms324 MB
dartr1.3–4.2 s0.0 ms0.95 / 12 ms0.7 ms / 85 ms675 MB
Flutter packages/flutterdart41.6 s* / 4.2 s0.4 ms3.8 / 45 ms257 ms / 13.8 s371 MB
dartr2.0–6.1 s0.1 ms2.2 / 62 ms5.8 ms / 5.9 s858 MB
Flutter applicationdart93.0 s / 40.3 s0.4 ms4.8 / 53 ms40 ms / 6.0 s3,410 MB
dartr33.0 s (18.2–47.7 s)0.0 ms1.2 / 34 ms0.4 ms / 0.94 s3,138 MB

* Short load spike (load average 28) at the start of the Flutter language-server run.

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 matches dart language-server on 8,876 sampled requests across 42 pub packages and registers every capability (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: similar to Dart's for dartr analyze on packages (lower on Flutter and the full application; 103 to 122 MB on packages with a warm --cache) and about 2 times Dart's for dartr language-server on packages (slightly lower on the full application; see the memory charts).
  • Disk cache: dartr analyze has an optional disk cache (--cache / DARTR_CACHE_DIR, off by default); dartr language-server analyzes from source on every run, so a warm dart language-server can start faster on packages (1.4 s vs 0.9–3.7 s on flutter_tools, 1.9 s vs 1.3–4.2 s on analyzer 9.0.0, 4.2 s vs 2.0–6.1 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.