Skip to content

feat: add vitest doctor - #10710

Merged
sheremet-va merged 3 commits into
feat/perf-hintsfrom
feat/perf-diagnostics
Aug 7, 2026
Merged

sheremet-va merged 3 commits into
feat/perf-hintsfrom
feat/perf-diagnostics

Conversation

@sheremet-va

@sheremet-va sheremet-va commented Jul 4, 2026 •

Copy link
Copy Markdown
Member

Part 3 of 3 of the perf discoverability work. Stacked on #10821 (performance hints), which is stacked on #10820 (duration breakdown percentages) — only the last commits are new here.

vitest doctor turns the hints' estimate into a measurement: resolves the config, prunes candidates from it (threads, vmThreads for DOM suites, environment: 'happy-dom' for jsdom projects, isolate: false, threads + isolate: false as the honest competitor for vm-pool configs, and fsModuleCache: true when the cache is off), runs the suite under each, and recommends with a ready-to-paste snippet:

Results (min of 3 runs each)

  baseline (pool: forks · isolate: true)  4.08s
  pool: 'threads'                         3.64s (-11%)
  pool: 'vmThreads'                       1.33s (-67%)
  isolate: false                          1.28s (-69%)

Recommendation: pool: 'vmThreads' (-67%)

  // vitest.config.ts
  import { defineConfig } from 'vitest/config'

  export default defineConfig({
    test: {
      pool: 'vmThreads', // measured -67% on this suite
    },
  })
  • isolate: false is validated with two shuffled-order runs (explicit distinct seeds, so a user-pinned sequence.seed can't silently produce the same order twice); a failing validation excludes the candidate and reports which tests depend on isolation.
  • Failing candidates print an excerpt of their errors — "this suite can't move to vmThreads" comes with the reason.
  • "Keep the current configuration" is always a measured verdict: even with no candidates the baseline is measured and reported.
  • Every measured run executes through a generated runner script (createVitest + JSON overrides) instead of the CLI binary, so the baseline and every candidate pay the identical entry cost, and candidates can express what CLI flags cannot: environment: 'happy-dom' swaps the environment of jsdom projects only — other projects keep theirs (covered by a fixture whose node project fails if the swap leaks). Offered whenever any project runs jsdom and the package actually resolves — checked with import.meta.resolve from the vitest package, which is exactly how the environment imports it. A recommendation comes with a "happy-dom implements the DOM differently" caveat.
  • fsModuleCache: true gets one untimed priming run before its measured reps (candidates support primeRuns), so the reported number is what repeated runs pay with a populated cache — consistent with the warm steady state everything else is measured in.
  • The baseline always gets ≥2 runs so a cold first run (which warms caches for everyone) is never compared against warm candidates; candidates near-tied with the fastest are resolved in favor of the one that keeps isolation.
  • Every measurement runs the full suite, browser projects included — isolate: false affects browser mode too, and a recommendation is only honest when measured on the run the user actually pays for. Candidates that cannot affect browser projects (pool, environment, the fs cache) are still picked from the node-side projects only, and a browser-only workspace still gets the isolate: false candidate and the maxWorkers probes. Candidates are killed after 4× the baseline duration; SIGINT/SIGTERM kills the active child.
  • Doctor also probes lower maxWorkers values on top of the winning configuration - every worker funnels transforms through the single main-thread Vite server, so past a certain count more workers are slower. Greedy descent from half the current count, keeping a step only when it's ≥5% faster:
  measuring maxWorkers: 4 (with pool: 'vmThreads')... 0.94s
  measuring maxWorkers: 2 (with pool: 'vmThreads')... 1.12s

Recommendation: pool: 'vmThreads' + maxWorkers: 4 (-74%)

Docs: vitest doctor in cli.md, plus the doctor pointers in improving-performance.md and config/experimental.md.

}

// provenance must be captured before the defaults are merged in
const providedOptions = captureProvidedOptions(viteConfigTest, options)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the config shenanigans would look better after we merge the config refactor

@sheremet-va
sheremet-va force-pushed the feat/perf-diagnostics branch from 25bc8ae to 5ed9d9e Compare July 4, 2026 14:23
@sheremet-va
sheremet-va changed the base branch from perf/warm-modules to main July 7, 2026 10:22
@sheremet-va
sheremet-va force-pushed the feat/perf-diagnostics branch from 5ed9d9e to 12ca18c Compare July 7, 2026 10:23
@netlify

netlify Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 81d33e8
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a622a283aa5d100077a381e
😎 Deploy Preview https://deploy-preview-10710--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va

Copy link
Copy Markdown
Member Author

@hi-ogawa forgot to ask for review 😢

@sheremet-va
sheremet-va requested a review from AriPerkkio July 22, 2026 12:44
@sheremet-va

Copy link
Copy Markdown
Member Author

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.

Technically, it should also remove the time it takes to load the module graph

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:

Should also note that on CI this doesn't help. Plus it's not longer in experimental

environment: 'happy-dom' is only offered when every project runs jsdom (the CLI override hits all projects at once) and the package actually resolves — checked with import.meta.resolve from the vitest package, which is exactly how the environment imports it. A recommendation comes with a "happy-dom implements the DOM differently" caveat.

We should manually update the config for every project (do we have APIs that could do that?), "all projects use jsdom" is pretty useless as one will probably use a combination of environments

Browser projects are excluded from the measurements via --project (no candidate affects them; they'd only dilute deltas); candidates are killed after 4× the baseline duration; SIGINT/SIGTERM kills the active child.

We should always run all tests. isolation also affects browser mode, for example.

@sheremet-va sheremet-va changed the title feat: report duration breakdown percentages, print performance hints, add vitest doctor feat: add vitest doctor Jul 23, 2026
@sheremet-va
sheremet-va changed the base branch from main to feat/perf-hints July 23, 2026 15:09
@sheremet-va
sheremet-va force-pushed the feat/perf-diagnostics branch from 81d33e8 to 58ea253 Compare July 23, 2026 15:10
@sheremet-va
sheremet-va force-pushed the feat/perf-hints branch 2 times, most recently from 5971d13 to fd3342a Compare July 23, 2026 16:09
Measures how much faster the suite runs under alternative configurations
by running it under each of them, and recommends the fastest with a
ready-to-paste config snippet. Candidates run through a generated runner
script so the happy-dom candidate can swap the environment of jsdom
projects only; every measured run includes browser projects.
@sheremet-va
sheremet-va force-pushed the feat/perf-diagnostics branch from 58ea253 to 54b77d0 Compare July 23, 2026 16:09
offer each vm pool whenever the suite does not already run it - vmForks can beat vmThreads (per-process heap and GC)
@sheremet-va
sheremet-va merged commit 549ccfd into feat/perf-hints Aug 7, 2026
22 of 24 checks passed
@sheremet-va
sheremet-va deleted the feat/perf-diagnostics branch August 7, 2026 12:39
@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