Skip to content

feat: print performance hints after the run (experimental.diagnostics) - #10821

Merged
sheremet-va merged 3 commits into
feat/duration-breakdownfrom
feat/perf-hints
Aug 7, 2026
Merged

sheremet-va merged 3 commits into
feat/duration-breakdownfrom
feat/perf-hints

Conversation

@sheremet-va

Copy link
Copy Markdown
Member

Split out of #10710 (part 2 of 3). Stacked on #10820 (duration breakdown percentages); vitest doctor follows.

When the collected timings show a config change would significantly speed up the run, the summary is followed by a hint (at most one of the isolate family per run, the most specific one), gated behind experimental.diagnostics: boolean | { isolate?, environment?, import?, transform? }.

Isolate hint — the pool now tracks how long each worker start takes (spawn + bundle load + environment setup, summed as state.startupTime / state.workersSpawned); when isolate: true spends a significant share of the run spawning a fresh worker per test file, the summary estimates what isolate: false would save. Reused workers also keep evaluated modules alive, so the estimate includes the module evaluations later files skip — per-module evaluation times exist only when experimental.importDurations is collected, so without it the hint reports the spawn saving alone as a lower bound ("at least ~12.5s faster").

Environment hint — for DOM suites (≥2s and ≥25% of a project's tracked time spent re-creating jsdom/happy-dom per file):

Environment  jsdom was created 40 times · 23.80s total, 79% of tracked time
             create it once per worker with pool: 'vmThreads' (keeps per-file isolation) or isolate: false (shares it across files)
             learn more: https://vitest.dev/guide/improving-performance#test-environments

Import hint — import-dominated suites previously got no hint at all. Barrel-style imports re-evaluate the same module graph for every isolated test file; the server already records how many times it served each module (state.metadata[project].duration), so the hint measures the duplication exactly — suites whose files import mostly disjoint graphs stay quiet, because reusing workers wouldn't reduce their import work. On an 800-module barrel fixture (20 test files importing a few symbols each through the root index):

Import  837 modules were evaluated 16360 times · 15.21s total, 66% of tracked time
        ~928ms faster with isolate: false — shared modules are evaluated once per worker instead of once per file
        learn more: https://vitest.dev/guide/improving-performance#test-isolation

(measured: isolate: false takes that fixture from 2.05s to 1.25s)

Transform hint — when transforms dominate instead (≥2s and ≥25% of tracked time) and nothing persists them, the hint points at the fs module cache; it only speaks up when the import hint didn't (e.g. isolate was set explicitly), so the two disclose progressively. On CI the cache directory is discarded with the runner unless explicitly persisted, so the hint adds a line saying exactly that:

Transform  transforming modules took 7.00s · 40% of tracked time, re-done on every run
           persist transforms across runs with fsModuleCache: true
           on CI this only helps when the cache directory is persisted between runs
           learn more: https://vitest.dev/guide/improving-performance#caching-between-reruns
  • The per-project transform split rides on the union-of-inflight-intervals clock from perf: reuse compiled code across vm pool contexts and prewarm the module graph #10744: transformStarted/transformFinished take the project name (derived in ModuleFetcher from its config), so per-project times are busy-window measurements, not summed per-fetch wall times.
  • Hints never suggest changing an option the user set explicitly. Provenance is captured before configDefaults is merged into the options (captureProvidedOptions in resolveTestConfig, from the raw options and viteConfig.test) — computing it later sees defaults as user values.
  • A hint has to be worth acting on: the estimated saving must be ≥5% of the run (or ≥10s on long runs).
  • Hints print in CI too, and are suppressed in watch mode and --merge-reports runs (blobs replay past durations; no environments were created by the merge process).

Docs: experimental.diagnostics in config/experimental.md; improving-performance.md gained "Test Environments" (the trade-off table the environment hint links to) and the hint pointer in "Profile First".

…at/perf-hints

# Conflicts:
#	docs/guide/improving-performance.md
#	packages/vitest/src/node/environments/fetchModule.ts
#	packages/vitest/src/node/state.ts
@sheremet-va
sheremet-va merged commit afc3d26 into feat/duration-breakdown Aug 7, 2026
22 of 24 checks passed
@sheremet-va
sheremet-va deleted the feat/perf-hints branch August 7, 2026 13:12
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant