blob: cb1e9b433e2e46e964b33fa8245750c13b7d58b7 [file] [view] [edit]
# Analysis Server Benchmark Scenarios
This document explains the benchmark scenarios in `pkg/analysis_server/tool/benchmark_tools/`: what real IDE or CLI behavior each one models, who is affected, and how its numbers relate to real repositories. Synthetic benchmarks are easy to dismiss as contrived, or to over-optimize, unless their inputs are tied to real workflows. Benchmarks that analyze real code do not have this problem, but their inputs change over time, so it has to be clear which numbers can be compared.
## Warm startup of a multi-package workspace with IDE excludes
`single_benchmarks/warm_startup_multi_package_with_ide_excludes.dart`
```bash
out/ReleaseX64/dart-sdk/bin/dart \
pkg/analysis_server/tool/benchmark_tools/single_benchmarks/warm_startup_multi_package_with_ide_excludes.dart
```
It accepts only `--dart=<path>` and `--json`; the scenarios and the sweep are fixed in code, so every run produces the same comparable report.
### What it simulates
A pub workspace with 25, 50, or 100 packages, 50 small Dart libraries per package, one shared `.dart_tool/package_config.json`, opened as a single included root. For each package count, four scenarios run AOT `dart language-server` with a persistent disk cache (`--cache`):
- `legacy_3p_excludes`: `--protocol=analyzer`, 3 excludes per package (`<package>/.dart_tool`, `<package>/.pub`, `<package>/build`) sent in `analysis.setAnalysisRoots`. This is IntelliJ and Android Studio today.
- `legacy_no_excludes`: `--protocol=analyzer`, no excludes. This is the control for `legacy_3p_excludes`.
- `lsp_3p_excludes`: `--protocol=lsp`, the same excludes sent as `analysisExcludedFolders` in the `workspace/configuration` response. VS Code sends none by default (Dart-Code 3.147), so this models users who configured excludes, and a possible future IntelliJ client that uses LSP.
- `lsp_no_excludes`: `--protocol=lsp`, no excludes. This is the control for `lsp_3p_excludes`, and the default for VS Code.
Each scenario first runs a cold analysis to fill the cache, then 3 fresh server processes against the filled cache. The measured time is from sending `analysis.setAnalysisRoots` (legacy) or `initialized` (LSP) until analysis finishes, so it includes root discovery, file listing, and watcher setup, but not process launch.
The workspace root path is padded to 64 characters, and the report prints the actual length. The server compares paths character by character, so without padding the result would depend on the temp directory: on one Linux machine, a 128-character common prefix of the package paths instead of an 80-character one raised the exclude overhead at 100 packages from 1,059 ms to 1,533 ms.
### Why these inputs happen
- IntelliJ and Android Studio run the analysis server with the legacy protocol, and bridge LSP features in process ([`lsp/ABOUT.md`](https://github.com/flutter/dart-intellij-third-party/blob/75ae85549a97ead55e9496255eba8af803991308/third_party/src/main/java/com/jetbrains/lang/dart/lsp/ABOUT.md)). On project open, `DartStartupActivity` finds every `pubspec.yaml` in the project and excludes `.dart_tool`, `.pub`, and `build` next to it ([`DartStartupActivity.kt#L166-L180`](https://github.com/flutter/dart-intellij-third-party/blob/75ae85549a97ead55e9496255eba8af803991308/third_party/src/main/java/com/jetbrains/lang/dart/DartStartupActivity.kt#L166-L180), [`#L246-L247`](https://github.com/flutter/dart-intellij-third-party/blob/75ae85549a97ead55e9496255eba8af803991308/third_party/src/main/java/com/jetbrains/lang/dart/DartStartupActivity.kt#L246-L247)). `DartServerRootsHandler` sends every module content root as `included`, and every excluded folder of it, except `packages`, as `excluded` ([`DartServerRootsHandler.java#L88-L101`](https://github.com/flutter/dart-intellij-third-party/blob/75ae85549a97ead55e9496255eba8af803991308/third_party/src/main/java/com/jetbrains/lang/dart/analyzer/DartServerRootsHandler.java#L88-L101)).
- With LSP, `LspAnalysisServer` applies each relative entry of `dart.analysisExcludedFolders` to every workspace folder, so the number of excluded paths is the number of entries times the number of workspace folders. Both protocols pass the included and excluded paths to the same `AbstractNotificationManager` and `ContextManager`.
The server checks every analyzed file against every included and excluded root, in `AbstractNotificationManager._isIncluded` and `ContextRootImpl._isExcluded`, and against every package of the package config, in `Packages.packageForPath`. Each check scans the paths character by character, so the cost of the root checks is proportional to `fileCount * (includedCount + excludedCount) * pathLength`. Here the number of files and the number of excludes both grow with the number of packages, so the cost grows quadratically.
### Who is affected
- Affected: IntelliJ and Android Studio users with a multi-package repository in one window (pub workspaces, melos monorepos, Flutter plugins with `example/` and subpackages, multi-module projects), and VS Code users with many workspace folders or with `dart.analysisExcludedFolders`.
- Not meaningfully affected: one package opened alone (1 included root, at most 3 excludes). There, `isWithin` is about 2–3% of warm startup (about 60 ms for `pkg/analyzer` on an Apple M4 Pro).
### Metrics
- Primary: warm initial analysis time, median of 3 runs, for each scenario and package count.
- Headline: the exclude overhead, the warm median of a scenario with excludes minus that of the scenario without excludes with the same protocol, printed as a separate table. The protocols differ in costs that do not depend on the excludes: for example, the legacy server sends `analysis.errors` for every file, even without errors, while the LSP server publishes diagnostics only for files that have them. Fixes should bring it close to zero at every package count. If it grows with the package count again, that is a regression. A change that speeds up every file, with or without excludes, also speeds up the control, so the overhead does not show it; compare the warm medians too.
The generated libraries are tiny, so reading, linking, and diagnostics cost much less than in real code. Relative speedups here are therefore much larger than in real repositories. Report the absolute milliseconds saved, and check the real impact on a real repository, as in the calibration below.
### Real-world calibration
The Dart SDK repository, opened in IntelliJ, sends 32 included and 292 excluded roots (96 packages times `.dart_tool`, `.pub`, and `build`, plus 4 others); 6,618 files are analyzed, and the package config has 190 packages. Replaying that `analysis.setAnalysisRoots` payload against AOT `dart language-server --protocol=analyzer` with a filled cache (commit `256206b002e`, 2026-11-20, macOS, Apple M4 Pro):
- Warm startup: median 6,320 ms (runs: 6,706, 6,306, 6,320 ms).
- In a separate run under the sampling profiler (250 µs period), `isWithin` takes about 24% of CPU (about 1.5 s of the 6.3 s), two thirds of it in `AbstractNotificationManager._isIncluded`.
- Control: `pkg/analyzer` alone (1,625 files, no excludes) has a warm median of 1,984 ms, of which `isWithin` is about 3% (about 60 ms). Adding 496 excludes raises the median to 2,250 ms and `isWithin` to about 18%.
After the optimizations below, the same IntelliJ project was replayed on Linux x64 (AMD Ryzen 9 PRO 8945HS), with the server from before the optimizations (`f3091555445`) and the server after CL 580840 (product AOT, 3 interleaved rounds of 3 warm runs, mean of the warm medians). The payload is built from the `.iml` files of the project, as `DartServerRootsHandler` does: the content root of each module with the Dart SDK enabled is included, and its excluded folders and the `.idea` directory of the project are excluded. Six modules whose `.iml` files are not in this checkout, three of them outside the repository, are left out, which gives 30 included and 287 excluded roots.
| Scenario | Before | After |
|---|---:|---:|
| With the excludes | 5,022 ms | 3,724 ms (−26%) |
| The same included roots, without excludes | 3,967 ms | 3,755 ms (−5%) |
| Exclude overhead | +1,055 ms | −31 ms |
After the optimizations the overhead is negative, because without the excludes the server also analyzes the files in the excluded folders.
The same replay on macOS (Apple M4 Pro, 32 included and 292 excluded roots, 6,720 analyzed files, product AOT from the same commits, 3 interleaved rounds of 3 warm runs against a shared filled cache) hits frequent `+1,000 ms` retries inside `analysis.setAnalysisRoots` when registering 32 FSEvents watchers (`TimerUtils::Sleep(1000)` in `runtime/bin/file_system_watcher_macos.cc`, occurring on 20 of the 36 runs, including one 10-second spike). Combining the median 0-retry `analysis.setAnalysisRoots` response time with the median post-`analysis.setAnalysisRoots` analysis time across all 9 warm runs (taking the median of only the 0-retry runs directly gives `6,955 → 5,410 ms`, −22%):
| Scenario | Before | After |
|---|---:|---:|
| With the excludes | 6,960 ms | 5,466 ms (−21%) |
| The same included roots, without excludes | 5,736 ms | 5,457 ms (−5%) |
| Exclude overhead | +1,224 ms | +9 ms |
The −1,494 ms saved with excludes matches the ~1.5 s sampling-profiler estimate above; the percentage is smaller than on Linux (−21% vs −26%) because macOS pays ~2.3 s in `analysis.setAnalysisRoots` watcher setup even at 0 retries. Both scenarios analyze the same 6,720 files here (the only existing non-dot excluded directory with Dart files is `pkg/front_end/testcases`, already excluded by `pkg/front_end/analysis_options_no_lints.yaml`), so the exclude overhead drops to noise (+9 ms) rather than turning negative.
### Baseline before the optimizations
Linux x64, AMD Ryzen 9 PRO 8945HS, 2026-11-21, server from an SDK built at `51133fc5559` (2026-11-18), workspace root path length 64.
| Scenario | Packages | Files | Excluded | Cold | Warm runs (ms) | Warm median |
|---|---:|---:|---:|---:|---|---:|
| legacy_3p_excludes | 25 | 1250 | 75 | 1025 ms | 262, 261, 264 | **262 ms** |
| lsp_3p_excludes | 25 | 1250 | 75 | 1073 ms | 251, 248, 253 | **251 ms** |
| lsp_no_excludes | 25 | 1250 | 0 | 993 ms | 182, 183, 183 | **183 ms** |
| legacy_3p_excludes | 50 | 2500 | 150 | 2098 ms | 675, 659, 653 | **659 ms** |
| lsp_3p_excludes | 50 | 2500 | 150 | 2059 ms | 627, 621, 620 | **621 ms** |
| lsp_no_excludes | 50 | 2500 | 0 | 1823 ms | 367, 369, 367 | **367 ms** |
| legacy_3p_excludes | 100 | 5000 | 300 | 4759 ms | 1786, 1780, 1805 | **1786 ms** |
| lsp_3p_excludes | 100 | 5000 | 300 | 4623 ms | 1751, 1741, 1771 | **1751 ms** |
| lsp_no_excludes | 100 | 5000 | 0 | 3624 ms | 727, 707, 719 | **719 ms** |
Exclude overhead:
| Packages | legacy_3p_excludes | lsp_3p_excludes |
|---:|---:|---:|
| 25 | +79 ms | +68 ms |
| 50 | +292 ms | +254 ms |
| 100 | +1067 ms | +1032 ms |
Each doubling of the package count multiplies the overhead by about 3.7–4.1, consistent with quadratic growth. At 100 packages, the excludes take 59% of the warm startup. With a 48-character `TMPDIR`, the overhead at 100 packages was +1073 ms and +1019 ms, so the padding works.
Here and in the Optimizations entries below, up to "A control for each protocol", the overhead of both scenarios was computed against `lsp_no_excludes`. So the overhead of `legacy_3p_excludes` there includes costs of the legacy protocol that do not depend on the excludes: 58 ms at 100 packages with the server of CL 580800.
### Optimizations
Each entry is measured against its parent commit, on the machine of the baseline above (product AOT, mean of 2 interleaved rounds). Profiles are of the whole server process, from launch to exit, all threads, in the 3 warm runs of `lsp_3p_excludes` at 100 packages (non-product AOT, `perf record -e instructions:u -c 1000000 -g`, mean of the 3 runs). A row "with callees" counts every sample that has that code anywhere on its stack, including inlined frames. With smaller sampling periods the kernel throttles sampling, and the profile undercounts by up to 3 times; with this one, the totals match `perf stat` within 1%. Without `perf`, the non-product server's warm medians are within 1% of the product ones, so the profiles represent the product build.
#### [CL 580541](https://dart-review.googlesource.com/c/sdk/+/580541): Cache `AbstractNotificationManager._isIncluded` per file path
`_isIncluded` ran for every analysis result, twice for the first result for each file. Its result depends only on the path and the analysis roots, so it is now cached per path, and the cache is cleared when the roots change.
Warm medians:
| Packages | legacy_3p_excludes | lsp_3p_excludes | lsp_no_excludes |
|---:|---:|---:|---:|
| 25 | 266 → 241 ms | 252 → 226 ms | 184 → 184 ms |
| 50 | 651 → 561 ms | 625 → 533 ms | 367 → 369 ms |
| 100 | 1779 → 1437 ms | 1758 → 1381 ms | 713 → 710 ms |
Exclude overhead:
| Packages | legacy_3p_excludes | lsp_3p_excludes |
|---:|---:|---:|
| 25 | 82 → 57 ms | 68 → 42 ms |
| 50 | 285 → 193 ms | 258 → 165 ms |
| 100 | 1066 → 728 ms | 1045 → 672 ms |
Profile:
| | Before | After | Change |
|---|---:|---:|---:|
| All server instructions | 29.73G | 21.73G | −27% |
| `AbstractNotificationManager._isIncluded`, with callees | 16.21G (54.5%) | 8.08G (37.2%) | −50% |
| `ContextRootImpl._isExcluded`, with callees | 6.37G (21.4%) | 6.51G (30.0%) | unchanged |
| `package:path` code, with callees | 22.67G (76.2%) | 14.71G (67.7%) | −35% |
After this change, `isWithin` reached from `_isIncluded` (36.8%, once per file, but still over all included and excluded paths) and in `ContextRootImpl._isExcluded` (23.4%) is most of the remaining path cost.
#### [CL 580600](https://dart-review.googlesource.com/c/sdk/+/580600): Scan names under the root once in `ContextRootImpl._isExcluded`
Files and folders whose name, or the name of an ancestor under the context root, starts with `.` are excluded. This was checked by walking the ancestors with `Folder.contains`, `Context.basename`, and `Context.dirname`, each parsing the whole path, for every file, with or without excludes; now the names after the root are scanned once.
Warm medians:
| Packages | legacy_3p_excludes | lsp_3p_excludes | lsp_no_excludes |
|---:|---:|---:|---:|
| 25 | 241 → 226 ms | 226 → 213 ms | 183 → 170 ms |
| 50 | 554 → 534 ms | 529 → 508 ms | 364 → 339 ms |
| 100 | 1420 → 1388 ms | 1383 → 1331 ms | 708 → 685 ms |
Exclude overhead:
| Packages | legacy_3p_excludes | lsp_3p_excludes |
|---:|---:|---:|
| 25 | 59 → 56 ms | 43 → 43 ms |
| 50 | 190 → 195 ms | 165 → 170 ms |
| 100 | 713 → 703 ms | 676 → 646 ms |
The overhead does not change, because the check runs for every file in every scenario, including `lsp_no_excludes`.
Profile:
| | Before | After | Change |
|---|---:|---:|---:|
| All server instructions | 21.73G | 20.70G | −5% |
| `ContextRootImpl._isExcluded`, with callees | 6.51G (30.0%) | 5.51G (26.6%) | −15% |
| Ancestor walk in `_isExcluded` (`Context.basename`, `Context.dirname`, `Folder.contains`) | 0.98G (4.5%) | none | |
| `ContextRootImpl._hasDotNameUnderRoot`, with callees | none | 0.013G (0.06%) | |
| Fallback walk of the ancestors | none | 0 samples | |
| `package:path` code, with callees | 14.71G (67.7%) | 13.89G (67.1%) | −6% |
The check matters more for `dart analyze` of one large package with a filled cache, where everything else is cached, and the paths are long and deep. A second `dart analyze` of the `stable_analysis` tarball (a separate cache for each build, 7 interleaved rounds, product AOT) went from 7.72G to 6.69G instructions (−13%), and from 673 to 622 ms wall time (−8%). Its profile (non-product AOT, all processes, sampled every 200,000 instructions, which this workload allows without throttling):
| | Before | After | Change |
|---|---:|---:|---:|
| All instructions | 10.01G | 9.22G | −8% |
| `ContextRootImpl._isExcluded`, with callees | 0.958G (9.6%) | 0.010G (0.1%) | −99% |
| `ContextRootImpl._hasDotNameUnderRoot`, with callees | none | 0.008G (0.1%) | |
| `package:path` code, with callees | 1.375G (13.7%) | 0.437G (4.7%) | −68% |
#### [CL 580660](https://dart-review.googlesource.com/c/sdk/+/580660): Look up the ancestors of a path in `AbstractNotificationManager._isIncluded`
`_isIncluded` checked each file against every included and excluded path with `Context.isWithin` and `Context.equals`. Now a new `PathSubtreeSet` looks up the file and those of its ancestors that have the length of a root in a `PathSet` of `package:path`, so the cost no longer depends on the number of excludes.
Warm medians:
| Packages | legacy_3p_excludes | lsp_3p_excludes | lsp_no_excludes |
|---:|---:|---:|---:|
| 25 | 230 → 208 ms | 214 → 193 ms | 174 → 174 ms |
| 50 | 536 → 440 ms | 511 → 418 ms | 344 → 352 ms |
| 100 | 1386 → 1008 ms | 1337 → 950 ms | 690 → 694 ms |
Exclude overhead:
| Packages | legacy_3p_excludes | lsp_3p_excludes |
|---:|---:|---:|
| 25 | 56 → 34 ms | 41 → 18 ms |
| 50 | 192 → 89 ms | 167 → 67 ms |
| 100 | 696 → 314 ms | 647 → 257 ms |
Profile:
| | Before | After | Change |
|---|---:|---:|---:|
| All server instructions | 20.71G | 12.69G | −39% |
| `AbstractNotificationManager._isIncluded`, with callees | 8.08G (39.0%) | 0.061G (0.5%) | −99% |
| `PathSubtreeSet.containsSelfOrAncestor`, with callees | none | 0.056G (0.4%) | |
| `ContextRootImpl._isExcluded`, with callees | 5.47G (26.4%) | 5.55G (43.7%) | unchanged |
| `package:path` code, with callees | 13.87G (67.0%) | 6.00G (47.3%) | −57% |
After this change, `isWithin` in `ContextRootImpl._isExcluded` (41.9%) is most of the remaining exclude overhead.
#### [CL 580800](https://dart-review.googlesource.com/c/sdk/+/580800): Look up the ancestors of a path in `ContextRootImpl._isExcluded`
`_isExcluded` checked each file against every excluded path with `Context.isWithin`, both while listing the files of the context root and in `isAnalyzed` for every analysis result. Now `ContextRootImpl` keeps the excluded paths in a `PathSubtreeSet`, which `addExcluded` updates, so the cost no longer depends on the number of excludes.
Warm medians:
| Packages | legacy_3p_excludes | lsp_3p_excludes | lsp_no_excludes |
|---:|---:|---:|---:|
| 25 | 206 → 192 ms | 190 → 174 ms | 175 → 172 ms |
| 50 | 443 → 380 ms | 418 → 350 ms | 348 → 347 ms |
| 100 | 996 → 760 ms | 948 → 703 ms | 696 → 694 ms |
Exclude overhead:
| Packages | legacy_3p_excludes | lsp_3p_excludes |
|---:|---:|---:|
| 25 | 30 → 20 ms | 15 → 2 ms |
| 50 | 95 → 33 ms | 70 → 3 ms |
| 100 | 301 → 66 ms | 252 → 9 ms |
Profile:
| | Before | After | Change |
|---|---:|---:|---:|
| All server instructions | 12.68G | 6.97G | −45% |
| `ContextRootImpl._isExcluded`, with callees | 5.50G (43.4%) | 0.044G (0.6%) | −99% |
| `PathSubtreeSet.containsSelfOrAncestor`, with callees | 0.065G (0.5%) | 0.090G (1.3%) | |
| `package:path` code, with callees | 5.92G (46.7%) | 0.62G (8.9%) | −89% |
One of the 3 profiled runs after the change spent 0.56G more in GC than the other two, which adds 0.19G to the mean. The overhead of `lsp_3p_excludes` is now within the noise. The 66 ms of `legacy_3p_excludes` at 100 packages that remain do not depend on the excludes, see the next entry.
#### [CL 580820](https://dart-review.googlesource.com/c/sdk/+/580820): A control for each protocol
The overhead of `legacy_3p_excludes` was computed against `lsp_no_excludes`, so it included costs of the legacy protocol that do not depend on the excludes. Now each scenario with excludes is compared with the scenario without excludes with the same protocol, and the new `legacy_no_excludes` is the legacy control.
Measured with the server of CL 580800.
Warm medians:
| Packages | legacy_3p_excludes | legacy_no_excludes | lsp_3p_excludes | lsp_no_excludes |
|---:|---:|---:|---:|---:|
| 25 | 193 ms | 191 ms | 176 ms | 174 ms |
| 50 | 383 ms | 383 ms | 353 ms | 346 ms |
| 100 | 762 ms | 751 ms | 706 ms | 694 ms |
Exclude overhead, against `lsp_no_excludes` → against the control with the same protocol:
| Packages | legacy_3p_excludes | lsp_3p_excludes |
|---:|---:|---:|
| 25 | 19 → 2 ms | 3 ms |
| 50 | 37 → 0 ms | 7 ms |
| 100 | 69 → 11 ms | 12 ms |
The overhead of both scenarios is within the noise, so with the optimizations above, the IDE excludes cost about 10 ms at 100 packages in either protocol.
The legacy protocol costs more than LSP: `legacy_no_excludes` minus `lsp_no_excludes` is 17, 37, and 58 ms at 25, 50, and 100 packages. In a profile of the 3 warm runs of both controls at 100 packages, the legacy server executes 1.34G more instructions (7.04G → 8.38G):
- 0.57G to send `analysis.errors` for every file, even without errors, while the LSP server publishes diagnostics only for files that have them. Of these, 0.35G convert the path of the file to a URI in `Context.toUri`, about half of it in `Context.current`, which reads `Uri.base` on every call, even for an absolute path.
- 0.38G to send `analysis.flushResults` for every file at shutdown, after the measured time.
- 0.17G in `BulkFixProcessor`, which lists the files of every context root for `DartFixPromptManager`.
- 0.17G in GC and other threads.
#### [CL 580840](https://dart-review.googlesource.com/c/sdk/+/580840): Convert file paths to URIs without `Context.toUri` in `ClientUriConverter`
When the client sends `supportsUris: true`, as IntelliJ does with SDK 3.4 and newer, the legacy server converts the path of every file in `analysis.errors` and other notifications to a `file:` URI. `Context.toUri` did this by reading `Context.current`, which reads `Uri.base` on every call, splitting the path into segments, building a `Uri`, and converting it back to a string. Now `toClientFilePath` writes `file://` and the path, with the characters that are not allowed in a URI path percent-encoded. Windows UNC paths still use `Context.toUri`.
Measured with 4 interleaved rounds.
Warm medians:
| Packages | legacy_3p_excludes | legacy_no_excludes | lsp_3p_excludes | lsp_no_excludes |
|---:|---:|---:|---:|---:|
| 25 | 190 → 186 ms | 192 → 184 ms | 176 → 176 ms | 174 → 174 ms |
| 50 | 377 → 369 ms | 376 → 368 ms | 354 → 354 ms | 348 → 349 ms |
| 100 | 755 → 741 ms | 749 → 737 ms | 704 → 707 ms | 695 → 694 ms |
The cost of the legacy protocol, `legacy_no_excludes` minus `lsp_no_excludes`:
| Packages | Before | After |
|---:|---:|---:|
| 25 | 17 ms | 10 ms |
| 50 | 29 ms | 19 ms |
| 100 | 55 ms | 43 ms |
Profile of the 3 warm runs of `legacy_no_excludes` at 100 packages:
| | Before | After | Change |
|---|---:|---:|---:|
| All server instructions | 8.37G | 7.75G | −7% |
| `ClientUriConverter.toClientFilePath`, with callees | 0.66G (7.9%) | 0.038G (0.5%) | −94% |
| `AnalysisServer.handleAnalysisEvent`, with callees | 0.69G (8.2%) | 0.37G (4.8%) | −46% |
About half of the conversions are in `analysis.flushResults` at shutdown, after the measured time.
### Limitations
- It covers excludes sent by the IDE, not `analyzer: exclude:` globs in `analysis_options.yaml`, which go through `ContextRootImpl.excludedGlobs`.
- It uses one included root, because many separately watched roots on macOS occasionally add 1,000 ms retries (`TimerUtils::Sleep(1000)` in `runtime/bin/file_system_watcher_macos.cc`). Real IntelliJ workspaces often send many included roots, and in `_isIncluded` each included root costs about as much as an excluded one, so this underestimates them.
- The excluded folders do not exist on disk; the server still records and checks them, but skips no files while listing.
- In a profile of the warm runs, `Packages.packageForPath` gets no samples, while `_PhysicalFolder.contains`, mostly reached from it, is about 5% in the Dart SDK calibration, so this benchmark does not show that cost.
## `dart analyze` of packages of this repository
`single_benchmarks/dart_analyze_packages.dart`
```bash
out/ReleaseX64/dart-sdk/bin/dart \
pkg/analysis_server/tool/benchmark_tools/single_benchmarks/dart_analyze_packages.dart
```
It accepts only `--dart=<path>`, `--baseline-dart=<path>`, and `--json`; the scenarios are fixed in code, so every run produces the same comparable report. It takes about 1 minute, or about 4 minutes with `--baseline-dart`.
### What it simulates
Running `dart analyze` in this repository, with the sources as they are in `pkg/`, both cold (with an empty analysis cache) and warm (with a filled one):
- `analyzer`: `pkg/analyzer`, one large package.
- `several_packages`: 7 related packages, `analyzer`, `analysis_server`, and the smaller packages around them.
Each scenario runs one cold `dart analyze` process with a new cache (`--cache`) in a temp directory under `.dart_tool` of the repository, then 5 warm ones with the filled cache. The measured time is the whole process, including launch, because this is what the user waits for. The benchmark does not use the cache in the home directory. It does not use the temp directory of the system either, because that can be in memory: on one Linux machine, with the caches in `/tmp` (tmpfs), cold `analyzer` took about 1 s (7%) less, and a server with `EvictingFileByteStore` looked 4% to 6% slower cold than one with `SingleFileByteStore`, while on ext4 there was no difference. It fails if the cold run did not write the cache, because the server then uses a cache in memory, and every warm run would be cold.
### Who is affected
- Cold: CI jobs without a kept cache, a new checkout, the first run after an update of the SDK that invalidates the cache. Almost all of the time is linking, resolution, and diagnostics.
- Warm: people and scripts (Git hooks, presubmit checks) that run `dart analyze` repeatedly with a kept cache. IDE startup reads the same cache, so it shares most of this work.
### Metrics
For each scenario, separately for cold and warm:
- Primary: time, mean of the runs.
- Instructions (user space, all processes, mean of the runs), counted with `perf stat`, only on Linux.
- Peak memory: the peak resident memory of the largest process, which is the analysis server, mean of the runs, from `/usr/bin/time`, only on Linux. It is what a machine or container must have, not what stays live after a garbage collection.
The report also prints the commit of the sources, and for each scenario the number of Dart files and lines, the number of reported issues, and the number of nested `package_config.json` files. Each nested config creates an analysis context, and they are not all in the repository: `pkg/analyzer/tool/{ast,element,generators}` have their own only after `dart pub get`, and use a published analyzer. With out-of-date configs that gave `analyzer_utilities` different language versions, the warm time of `pkg/analyzer` was 42 ms (2.6%) higher than after `dart pub upgrade`, because the contexts replaced the linked bundles of each other in the cache.
### How to compare
The sources change with almost every commit, and they are also what is analyzed: in the 30 days before 2026-11-23 the 7 packages grew by 2.2% in lines, and analyzing the older sources with the same SDK took 1.0% less warm time and 1.8% fewer instructions. So:
- Run the benchmark with `--dart` of the SDK with the change, and `--baseline-dart` of the SDK without it, both built in the same way. Each is the `dart` executable in a whole SDK directory, because `dart analyze` runs the analysis server of its SDK. Both analyze the same sources, and the `lib` of the SDK of `--dart` (`--sdk-path`), so differences in `lib` and in the lengths of SDK paths are not measured; do not edit the sources while it runs.
- For each scenario it runs cold in the order baseline, change, change, baseline, each with a new cache, and then warm 5 times in the same order, each SDK with its last cache. This gives 2 cold and 10 warm runs of each SDK. Four separately built caches gave the same mean warm time, so one cache for each SDK is enough.
- For warm it prints the means, and the change with its approximate 95% range (Student's t, with the same variance of both SDKs). A range that includes 0 means that no change was shown. It assumes independent runs, but neighboring runs are slightly similar (correlation 0.24 of the times), and other differences between invocations are not included. One of 20 ranges does not include the true change even without a problem, so in a table of 6 warm cells one wrong cell is not unusual. Comparing an SDK to itself in 3 invocations gave warm time ranges that include 0 in all 6 cells. Instructions differ more between invocations than between runs, so their ranges are too narrow: for warm `several_packages` one invocation gave +0.5% ± 0.4. Changes of that size are not shown, whatever their ranges.
- For cold it prints both runs of each SDK, without a range, because 2 runs say too little about their spread. To see a small change of cold, run the benchmark several times.
- For peak memory it prints the means (cold: the runs), without a change. Its differences between invocations are larger than its range: comparing an SDK to itself gave warm `several_packages` from −1.2% to +1.2%, with ranges that did not include 0, and cold from −4.3% to +3.4%.
- Cold peak memory varies much more than warm. In 32 cold runs of `several_packages` with the same SDK, peak memory was from 2352 to 2530 MiB, in many runs near 2360 or near 2500, and both can follow each other. The cause is not known.
- Do not compare the results of different commits or machines.
### Baseline
Linux x64, AMD Ryzen 9 PRO 8945HS, 2026-11-30, product AOT server compiled from `c26e1d38c52` (VM and `lib` from `3662148bfa6`), sources from `c26e1d38c52` with this benchmark, caches on ext4, the baseline of one invocation (cold: mean of 2 runs, warm: mean of 10 runs).
| Scenario | Files | Lines | Nested configs | Issues |
|---|---:|---:|---:|---:|
| analyzer | 1624 | 1,567,951 | 3 | 0 |
| several_packages | 4403 | 2,473,286 | 4 | 0 |
| Scenario | Mode | Time | Instructions | Peak memory |
|---|---|---:|---:|---:|
| analyzer | cold | **16761 ms** | 163.21G | 1441 MiB |
| analyzer | warm | **1676 ms** | 16.78G | 498 MiB |
| several_packages | cold | **27671 ms** | 261.80G | 2548 MiB |
| several_packages | warm | **2532 ms** | 25.59G | 668 MiB |
### Optimizations
Each entry is measured against its parent commit, with the same sources, on the machine of the baseline above (product AOT, `--baseline-dart`). Profiles are of all processes, from launch to exit, all threads, in 3 warm runs of `analyzer` (product AOT, `perf record -e instructions:u -c 1000000 -g`, mean of the 3 runs). A row "with callees" counts every sample that has that code anywhere on its stack.
#### [CL 581142](https://dart-review.googlesource.com/c/sdk/+/581142): Always read `xxh64` words through a typed data view
`SingleFileByteStore` verifies the `xxh64` checksum of every value that it reads. The words were read through two list types, so AOT did not inline the reads. Now they are always read through a typed data view.
| Scenario | Mode | Time | Instructions | Peak memory |
|---|---|---:|---:|---:|
| analyzer | cold | 16809, 16713 → 16392, 16660 ms (−1.4%) | 163.11, 163.31 → 160.49, 161.46 G (−1.4%) | 1435, 1447 → 1523, 1431 MiB |
| analyzer | warm | 1676 → 1567 ms (−6.5% ± 0.9) | 16.78 → 16.03 G (−4.4% ± 0.4) | 498 → 496 MiB |
| several_packages | cold | 27807, 27535 → 27273, 27482 ms (−1.1%) | 261.94, 261.65 → 260.98, 260.91 G (−0.3%) | 2559, 2536 → 2495, 2499 MiB |
| several_packages | warm | 2532 → 2363 ms (−6.7% ± 0.9) | 25.59 → 24.36 G (−4.8% ± 0.6) | 668 → 654 MiB |
Warm profile:
| | Before | After | Change |
|---|---:|---:|---:|
| All instructions | 16.72G | 15.98G | −4.4% |
| `xxh64`, with callees | 1.29G (7.7%) | 0.44G (2.7%) | −66% |
| `SingleFileByteStore.get`, with callees | 2.40G (14.3%) | 1.57G (9.8%) | −35% |
The time improves more than the instructions, probably because the removed ones were slow: the reads were calls, and allocated objects for values that do not fit into a Smi.
#### Count only analyzed files as immediate in context structure analytics
When analysis completes, `AnalysisServer.reportAnalysisAnalytics` computes statistics for the `contextStructure` event, with analytics enabled or not. It counted every known file under the root of a context as immediate, and computed the library cycle of each of their libraries. In this repository the root is the repository itself, and analysis knows many files under it without computing their cycles: doc imports of libraries that are not analyzed, and URIs of conditional imports that are not selected. So this read the files that their imports reach: in warm `analyzer` 933 files, of which 669 come from one `@docImport` of `package:compiler` in `utf8_bytes_scanner.dart` of `_fe_analyzer_shared`, and 222 from the `dart.library.js_interop` import of `package:http`. Now immediate files are the files that the driver analyzes, whose cycles analysis has already computed.
| Scenario | Mode | Time | Instructions | Peak memory |
|---|---|---:|---:|---:|
| analyzer | cold | 16492, 16301 → 15651, 15646 ms (−4.6%) | 161.29, 161.59 → 154.64, 153.26 G (−4.6%) | 1433, 1449 → 1427, 1505 MiB |
| analyzer | warm | 1582 → 1408 ms (−11.0% ± 0.7) | 16.05 → 14.24 G (−11.3% ± 0.2) | 495 → 464 MiB |
| several_packages | cold | 27284, 27467 → 27075, 27646 ms (−0.1%) | 259.13, 260.35 → 258.52, 257.42 G (−0.7%) | 2541, 2446 → 2456, 2557 MiB |
| several_packages | warm | 2379 → 2342 ms (−1.6% ± 1.0) | 24.42 → 24.01 G (−1.6% ± 0.5) | 655 → 645 MiB |
Warm profile:
| | Before | After | Change |
|---|---:|---:|---:|
| All instructions | 16.01G | 14.23G | −11.2% |
| `AnalysisServer.reportAnalysisAnalytics`, with callees | 1.37G (8.5%) | 0.016G (0.1%) | −99% |
| `LibraryCycleComputer.compute`, with callees | 5.03G (31.4%) | 3.64G (25.6%) | −28% |
| `FileSystemState._newFile`, with callees | 6.40G (40.0%) | 5.23G (36.8%) | −18% |
| Garbage collection marking (`MarkingVisitor`), with callees | 1.82G (11.4%) | 1.40G (9.8%) | −23% |
`reportAnalysisAnalytics` itself, with callees: time from builds with a `Stopwatch` around it (cold: 1 run, warm: mean of 5 runs), instructions from profiles (`analyzer` warm: mean of 3 runs, cold after: mean of 2 runs, others: 1 run):
| Scenario | Mode | Time | Instructions |
|---|---|---:|---:|
| analyzer | cold | 761 → 2.9 ms | 6.93G (4.3%) → 0.016G (0.01%) |
| analyzer | warm | 170 → 2.6 ms | 1.37G (8.5%) → 0.016G (0.1%) |
| several_packages | cold | 168 → 3.8 ms | 1.67G (0.6%) → 0.029G (0.01%) |
| several_packages | warm | 42 → 3.4 ms | 0.46G (1.9%) → 0.029G (0.1%) |
What remains are the loops over the known files; nothing under them reads or parses files, or computes library cycles. The time saved in `reportAnalysisAnalytics` is close to the change of the whole `analyzer` runs above: warm 167 ms against 174 ms, cold 758 ms against 748 ms. The benchmark runs `dart analyze` with `--suppress-analytics`, but the statistics are computed in the same way with analytics enabled, so the change is the same. Cold saves more time, because without a cache the new file states parse their files. In `several_packages` the change is small, because `utf8_bytes_scanner.dart` is analyzed there, and the key of its diagnostics includes the library cycles of its doc-imported libraries, so analysis itself reads the files of `package:compiler`; the analytics read 244 files, reached through conditional imports.
### Limitations
- It measures peak memory, not how much memory the analysis server retains, which is what matters in an IDE. `dart analyze` uses the product AOT runtime, which has no VM service, so it cannot run a full garbage collection and report the live heap.
- Cold has only 2 runs of each SDK with a baseline, and one without, so it shows only large changes of time, and even larger ones of peak memory.
- Instructions and peak memory are measured only on Linux.
- Peak memory is of one process, so it does not include the `dart` process that starts the server.
- It analyzes this repository, which has much generated and test code, and no errors. Code with many diagnostics spends more on them.
- The number of nested configs, so also the time, depends on the checkout.