Skip to content

Commit 2c2d1d4

Browse files
authored
perf!: remove minWorkers and set it automatically to 0 in non watch mode (#8454)
1 parent db6cd73 commit 2c2d1d4

File tree

22 files changed

+44
-178
lines changed

22 files changed

+44
-178
lines changed

docs/config/index.md

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,6 @@ export default defineConfig({
750750

751751
Maximum number or percentage of threads. You can also use `VITEST_MAX_THREADS` environment variable.
752752

753-
##### poolOptions.threads.minThreads<NonProjectOption />
754-
755-
- **Type:** `number | string`
756-
- **Default:** _available CPUs_
757-
758-
Minimum number or percentage of threads. You can also use `VITEST_MIN_THREADS` environment variable.
759-
760753
##### poolOptions.threads.singleThread
761754

762755
- **Type:** `boolean`
@@ -822,13 +815,6 @@ export default defineConfig({
822815

823816
Maximum number or percentage of forks. You can also use `VITEST_MAX_FORKS` environment variable.
824817

825-
##### poolOptions.forks.minForks<NonProjectOption />
826-
827-
- **Type:** `number | string`
828-
- **Default:** _available CPUs_
829-
830-
Minimum number or percentage of forks. You can also use `VITEST_MIN_FORKS` environment variable.
831-
832818
##### poolOptions.forks.isolate
833819

834820
- **Type:** `boolean`
@@ -885,13 +871,6 @@ export default defineConfig({
885871

886872
Maximum number or percentage of threads. You can also use `VITEST_MAX_THREADS` environment variable.
887873

888-
##### poolOptions.vmThreads.minThreads<NonProjectOption />
889-
890-
- **Type:** `number | string`
891-
- **Default:** _available CPUs_
892-
893-
Minimum number or percentage of threads. You can also use `VITEST_MIN_THREADS` environment variable.
894-
895874
##### poolOptions.vmThreads.memoryLimit<NonProjectOption />
896875

897876
- **Type:** `string | number`
@@ -966,13 +945,6 @@ export default defineConfig({
966945

967946
Maximum number or percentage of forks. You can also use `VITEST_MAX_FORKS` environment variable.
968947

969-
##### poolOptions.vmForks.minForks<NonProjectOption />
970-
971-
- **Type:** `number | string`
972-
- **Default:** _available CPUs_
973-
974-
Minimum number or percentage of forks. You can also use `VITEST_MIN_FORKS` environment variable.
975-
976948
##### poolOptions.vmForks.memoryLimit<NonProjectOption />
977949

978950
- **Type:** `string | number`
@@ -997,7 +969,7 @@ Be careful when using, it as some options may crash worker, e.g. --prof, --title
997969
- **Default:** `true`
998970
- **CLI:** `--no-file-parallelism`, `--fileParallelism=false`
999971

1000-
Should all test files run in parallel. Setting this to `false` will override `maxWorkers` and `minWorkers` options to `1`.
972+
Should all test files run in parallel. Setting this to `false` will override `maxWorkers` option to `1`.
1001973

1002974
::: tip
1003975
This option doesn't affect tests running in the same file. If you want to run those in parallel, use `concurrent` option on [describe](/api/#describe-concurrent) or via [a config](#sequence-concurrent).
@@ -1009,12 +981,6 @@ This option doesn't affect tests running in the same file. If you want to run th
1009981

1010982
Maximum number or percentage of workers to run tests in. `poolOptions.{threads,vmThreads}.maxThreads`/`poolOptions.forks.maxForks` has higher priority.
1011983

1012-
### minWorkers<NonProjectOption /> {#minworkers}
1013-
1014-
- **Type:** `number | string`
1015-
1016-
Minimum number or percentage of workers to run tests in. `poolOptions.{threads,vmThreads}.minThreads`/`poolOptions.forks.minForks` has higher priority.
1017-
1018984
### testTimeout
1019985

1020986
- **Type:** `number`

docs/guide/cli-generated.md

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,6 @@ Run tests inside a single thread (default: `false`)
411411

412412
Maximum number or percentage of threads to run tests in
413413

414-
### poolOptions.threads.minThreads
415-
416-
- **CLI:** `--poolOptions.threads.minThreads <workers>`
417-
- **Config:** [poolOptions.threads.minThreads](/config/#pooloptions-threads-minthreads)
418-
419-
Minimum number or percentage of threads to run tests in
420-
421414
### poolOptions.threads.useAtomics
422415

423416
- **CLI:** `--poolOptions.threads.useAtomics`
@@ -446,13 +439,6 @@ Run tests inside a single thread (default: `false`)
446439

447440
Maximum number or percentage of threads to run tests in
448441

449-
### poolOptions.vmThreads.minThreads
450-
451-
- **CLI:** `--poolOptions.vmThreads.minThreads <workers>`
452-
- **Config:** [poolOptions.vmThreads.minThreads](/config/#pooloptions-vmthreads-minthreads)
453-
454-
Minimum number or percentage of threads to run tests in
455-
456442
### poolOptions.vmThreads.useAtomics
457443

458444
- **CLI:** `--poolOptions.vmThreads.useAtomics`
@@ -488,13 +474,6 @@ Run tests inside a single child_process (default: `false`)
488474

489475
Maximum number or percentage of processes to run tests in
490476

491-
### poolOptions.forks.minForks
492-
493-
- **CLI:** `--poolOptions.forks.minForks <workers>`
494-
- **Config:** [poolOptions.forks.minForks](/config/#pooloptions-forks-minforks)
495-
496-
Minimum number or percentage of processes to run tests in
497-
498477
### poolOptions.vmForks.isolate
499478

500479
- **CLI:** `--poolOptions.vmForks.isolate`
@@ -516,13 +495,6 @@ Run tests inside a single child_process (default: `false`)
516495

517496
Maximum number or percentage of processes to run tests in
518497

519-
### poolOptions.vmForks.minForks
520-
521-
- **CLI:** `--poolOptions.vmForks.minForks <workers>`
522-
- **Config:** [poolOptions.vmForks.minForks](/config/#pooloptions-vmforks-minforks)
523-
524-
Minimum number or percentage of processes to run tests in
525-
526498
### poolOptions.vmForks.memoryLimit
527499

528500
- **CLI:** `--poolOptions.vmForks.memoryLimit <limit>`
@@ -544,13 +516,6 @@ Should all test files run in parallel. Use `--no-file-parallelism` to disable (d
544516

545517
Maximum number or percentage of workers to run tests in
546518

547-
### minWorkers
548-
549-
- **CLI:** `--minWorkers <workers>`
550-
- **Config:** [minWorkers](/config/#minworkers)
551-
552-
Minimum number or percentage of workers to run tests in
553-
554519
### environment
555520

556521
- **CLI:** `--environment <name>`

docs/guide/migration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ Vitest 4.0 removes some deprecated APIs, including:
238238
- Reporter APIs `onCollected`, `onSpecsCollected`, `onPathsCollected`, `onTaskUpdate` and `onFinished`. See [`Reporters API`](/advanced/api/reporters) for new alternatives. These APIs were introduced in Vitest `v3.0.0`.
239239
- `deps.external`, `deps.inline`, `deps.fallbackCJS` config options. Use `server.deps.external`, `server.deps.inline`, or `server.deps.fallbackCJS` instead.
240240
- `browser.testerScripts` config option. Use [`browser.testerHtmlPath`](/guide/browser/config#browser-testerhtmlpath) instead.
241+
- `minWorkers` config option. Only `maxWorkers` has any effect on how tests are running, so we are removing this public option.
241242

242243
This release also removes all deprecated types. This finally fixes an issue where Vitest accidentally pulled in `@types/node` (see [#5481](https://github.com/vitest-dev/vitest/issues/5481) and [#6141](https://github.com/vitest-dev/vitest/issues/6141)).
243244

docs/guide/parallelism.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ By default, Vitest runs _test files_ in parallel. Depending on the specified `po
1212
- `forks` (the default) and `vmForks` run tests in different [child processes](https://nodejs.org/api/child_process.html)
1313
- `threads` and `vmThreads` run tests in different [worker threads](https://nodejs.org/api/worker_threads.html)
1414

15-
Both "child processes" and "worker threads" are refered to as "workers". You can configure the number of running workers with [`minWorkers`](/config/#minworkers) and [`maxWorkers`](/config/#maxworkers) options. Or more granually with [`poolOptions`](/config/#pooloptions) configuration.
15+
Both "child processes" and "worker threads" are refered to as "workers". You can configure the number of running workers with [`maxWorkers`](/config/#maxworkers) option. Or more granually with [`poolOptions`](/config/#pooloptions) configuration.
1616

1717
If you have a lot of tests, it is usually faster to run them in parallel, but it also depends on the project, the environment and [isolation](/config/#isolate) state. To disable file parallelisation, you can set [`fileParallelism`](/config/#fileparallelism) to `false`. To learn more about possible performance improvements, read the [Performance Guide](/guide/improving-performance).
1818

packages/vitest/src/node/cli/cli-config.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ const poolThreadsCommands: CLIOptions<ThreadsOptions & WorkerContextOptions> = {
6666
description: 'Maximum number or percentage of threads to run tests in',
6767
argument: '<workers>',
6868
},
69-
minThreads: {
70-
description: 'Minimum number or percentage of threads to run tests in',
71-
argument: '<workers>',
72-
},
7369
useAtomics: {
7470
description:
7571
'Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: `false`)',
@@ -88,10 +84,6 @@ const poolForksCommands: CLIOptions<ForksOptions & WorkerContextOptions> = {
8884
description: 'Maximum number or percentage of processes to run tests in',
8985
argument: '<workers>',
9086
},
91-
minForks: {
92-
description: 'Minimum number or percentage of processes to run tests in',
93-
argument: '<workers>',
94-
},
9587
execArgv: null,
9688
}
9789

@@ -481,10 +473,6 @@ export const cliOptionsConfig: VitestCLIOptions = {
481473
description: 'Maximum number or percentage of workers to run tests in',
482474
argument: '<workers>',
483475
},
484-
minWorkers: {
485-
description: 'Minimum number or percentage of workers to run tests in',
486-
argument: '<workers>',
487-
},
488476
environment: {
489477
description:
490478
'Specify runner environment, if not running in the browser (default: `node`)',

packages/vitest/src/node/config/resolveConfig.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,12 @@ export function resolveConfig(
206206
resolved.maxWorkers = resolveInlineWorkerOption(resolved.maxWorkers)
207207
}
208208

209-
if (resolved.minWorkers) {
210-
resolved.minWorkers = resolveInlineWorkerOption(resolved.minWorkers)
211-
}
212-
213209
// run benchmark sequentially by default
214210
resolved.fileParallelism ??= mode !== 'benchmark'
215211

216212
if (!resolved.fileParallelism) {
217213
// ignore user config, parallelism cannot be implemented without limiting workers
218214
resolved.maxWorkers = 1
219-
resolved.minWorkers = 1
220215
}
221216

222217
if (resolved.maxConcurrency === 0) {
@@ -482,20 +477,6 @@ export function resolveConfig(
482477
}
483478
}
484479

485-
if (process.env.VITEST_MIN_THREADS) {
486-
resolved.poolOptions = {
487-
...resolved.poolOptions,
488-
threads: {
489-
...resolved.poolOptions?.threads,
490-
minThreads: Number.parseInt(process.env.VITEST_MIN_THREADS),
491-
},
492-
vmThreads: {
493-
...resolved.poolOptions?.vmThreads,
494-
minThreads: Number.parseInt(process.env.VITEST_MIN_THREADS),
495-
},
496-
}
497-
}
498-
499480
if (process.env.VITEST_MAX_FORKS) {
500481
resolved.poolOptions = {
501482
...resolved.poolOptions,
@@ -510,24 +491,8 @@ export function resolveConfig(
510491
}
511492
}
512493

513-
if (process.env.VITEST_MIN_FORKS) {
514-
resolved.poolOptions = {
515-
...resolved.poolOptions,
516-
forks: {
517-
...resolved.poolOptions?.forks,
518-
minForks: Number.parseInt(process.env.VITEST_MIN_FORKS),
519-
},
520-
vmForks: {
521-
...resolved.poolOptions?.vmForks,
522-
minForks: Number.parseInt(process.env.VITEST_MIN_FORKS),
523-
},
524-
}
525-
}
526-
527494
const poolThreadsOptions = [
528-
['threads', 'minThreads'],
529495
['threads', 'maxThreads'],
530-
['vmThreads', 'minThreads'],
531496
['vmThreads', 'maxThreads'],
532497
] as const satisfies [keyof PoolOptions, keyof ThreadsOptions][]
533498

@@ -538,9 +503,7 @@ export function resolveConfig(
538503
}
539504

540505
const poolForksOptions = [
541-
['forks', 'minForks'],
542506
['forks', 'maxForks'],
543-
['vmForks', 'minForks'],
544507
['vmForks', 'maxForks'],
545508
] as const satisfies [keyof PoolOptions, keyof ForksOptions][]
546509

packages/vitest/src/node/pools/forks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ export function createForksPool(
8585

8686
const maxThreads
8787
= poolOptions.maxForks ?? vitest.config.maxWorkers ?? recommendedCount
88-
const minThreads
89-
= poolOptions.minForks ?? vitest.config.minWorkers ?? Math.min(recommendedCount, maxThreads)
88+
const minThreads = vitest.config.watch
89+
? Math.min(recommendedCount, maxThreads)
90+
// avoid recreating threads when tests are finished
91+
: 0
9092

9193
const worker = resolve(vitest.distPath, 'workers/forks.js')
9294

packages/vitest/src/node/pools/threads.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ export function createThreadsPool(
6666

6767
const maxThreads
6868
= poolOptions.maxThreads ?? vitest.config.maxWorkers ?? recommendedCount
69-
const minThreads
70-
= poolOptions.minThreads ?? vitest.config.minWorkers ?? Math.min(recommendedCount, maxThreads)
69+
const minThreads = vitest.config.watch
70+
? Math.min(recommendedCount, maxThreads)
71+
// avoid recreating forks when tests are finished
72+
: 0
7173

7274
const worker = resolve(vitest.distPath, 'workers/threads.js')
7375

packages/vitest/src/node/pools/vmForks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ export function createVmForksPool(
9292

9393
const maxThreads
9494
= poolOptions.maxForks ?? vitest.config.maxWorkers ?? recommendedCount
95-
const minThreads
96-
= poolOptions.maxForks ?? vitest.config.minWorkers ?? Math.min(recommendedCount, maxThreads)
95+
const minThreads = vitest.config.watch
96+
? Math.min(recommendedCount, maxThreads)
97+
// avoid recreating forks when tests are finished
98+
: 0
9799

98100
const worker = resolve(vitest.distPath, 'workers/vmForks.js')
99101

packages/vitest/src/node/pools/vmThreads.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ export function createVmThreadsPool(
6969

7070
const maxThreads
7171
= poolOptions.maxThreads ?? vitest.config.maxWorkers ?? recommendedCount
72-
const minThreads
73-
= poolOptions.minThreads ?? vitest.config.minWorkers ?? Math.min(recommendedCount, maxThreads)
72+
const minThreads = vitest.config.watch
73+
? Math.min(recommendedCount, maxThreads)
74+
// avoid recreating threads when tests are finished
75+
: 0
7476

7577
const worker = resolve(vitest.distPath, 'workers/vmThreads.js')
7678

0 commit comments

Comments
 (0)