dart-best-practices
General best practices for Dart development. Covers code style, effective Dart, and language features.
Profile Dart command-line applications using the VM Service protocol to capture CPU samples and identify performance bottlenecks. Helps agents automate CPU profiling, generate function call breakdown summaries, and export JSON profiles without a browser or DevTools.
$ npx -y skills add kevmoo/dash_skills --skill profile-dart-code --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/profile-dart-codeContext preview
The summary Claude sees to decide when to auto-load this skill.
Profile Dart command-line applications using the VM Service protocol to capture CPU samples and identify performance bottlenecks. Helps agents automate CPU profiling, generate function call breakdown summaries, and export JSON profiles without a browser or DevTools.
name: profile-dart-code description: |- Profile Dart command-line applications using the VM Service protocol to capture CPU samples and identify performance bottlenecks. Helps agents automate CPU profiling, generate function call breakdown summaries, and export JSON profiles without a browser or DevTools. key_features: - Automated VM Service WebSocket connection - CPU sampling and top-function call summary - JSON trace export for further analysis
Guidelines and automated tools for capturing CPU profiles and identifying bottlenecks in Dart command-line applications.
or CLI tool.
overhead.
Do NOT profile using this skill when:
database queries, or disk I/O wait rather than CPU execution.
frame profiling, raster thread inspection, or widget rebuild tracking (use Flutter DevTools or `widget_inspector`).
milliseconds where VM warmup and sampling overhead skew results (use `package:benchmark_harness` or `package:bench_press` instead).
crashes on startup, fix functional bugs before attempting CPU profiling.
1. **Ensure clean compilation**: Make sure the target Dart script runs cleanly (`dart run <script.dart>`). 2. **Run Profiler Script**: Use the automated profiling helper script inside this skill directory to launch the target app with VM Service observability enabled, capture CPU samples, and output top-consuming functions. 3. **Analyze & Optimize**: Review the self and total sample percentages reported by the tool to pinpoint bottlenecks (e.g., excessive object allocation, costly hashing, virtual dispatch overhead).
This repository includes a zero-dependency (using only official `vm_service`) profiling script that launches any Dart file, connects to the VM Service, waits for execution to complete (`--pause-isolates-on-exit`), retrieves CPU samples, and prints a clean summary while exporting the full JSON profile.
Run it from any working directory:
dart run <dash_skills_repo>/skills/profile-dart-code/scripts/bin/profile.dart --out=cpu_profile.json -- <path_to_target.dart> [target_arguments...]
(default: `cpu_profile.json`).
= 1ms). Minimum `50`µs.
arguments passed to `main()`.
> [!WARNING] **Potential Hangs**: When profiling or debugging Dart targets using > VM services, target exceptions or connection issues can cause the process to > hang indefinitely. Ensure your target script handles timeouts, and monitor the > process output.
Connecting to VM service at ws://127.0.0.1:8181/ws... Target execution paused at exit. Retrieving CPU profile samples... === Top CPU Functions (Self Samples) === 1. _PuzzleSmart._shiftSlice (self: 34.2%, total: 41.0%) 2. _countInversions (self: 18.5%, total: 18.5%) 3. shortestPaths (self: 12.1%, total: 98.4%) Saved complete JSON profile to: cpu_profile.json
1. **Focus on Self % vs. Total %**: High `self %` indicates where CPU time is spent directly inside a function's own body (math, loop branching, array indexing). High `total %` with low `self %` indicates a dispatcher or outer orchestration loop. 2. **Look for Hidden Overhead**: Watch out for implicit object allocations (`_copyData`, iterator wrappers, closure creation) inside tight loops. 3. **Verify Optimizations Empirically**: Always record baseline sample counts and execution duration (`time -v`) before and after applying optimizations.
General best practices for Dart development. Covers code style, effective Dart, and language features.
Best practices for validating Dart documentation comments. Covers using `dart doc` to catch unresolved references and macros.
Guidelines for handling long lines in Dart code to adhere to the 80-column rule. The `lines_longer_than_80_chars` lint.
Best practices for using `expect` and `package:matcher`. Focuses on readable assertions, proper matcher selection, and avoiding…
Guidelines for using modern Dart features (v3.0 - v3.10) such as Records, Extension Types, Class Modifiers, Wildcards, Digit…
Guidelines and best practices for refactoring consecutive prints, single-line string concatenations, and complex output blocks…