Skip to content

Commit

Permalink
perf: use cpu cores more efficently (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Feb 8, 2022
1 parent 578258e commit 3df5d8b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/vitest/src/node/pool.ts
@@ -1,5 +1,6 @@
import { MessageChannel } from 'worker_threads'
import { pathToFileURL } from 'url'
import { cpus } from 'os'
import { resolve } from 'pathe'
import type { Options as TinypoolOptions } from 'tinypool'
import { Tinypool } from 'tinypool'
Expand Down Expand Up @@ -55,17 +56,20 @@ export function createFakePool(ctx: Vitest): WorkerPool {
}

export function createWorkerPool(ctx: Vitest): WorkerPool {
const threadsCount = ctx.config.watch
? Math.max(cpus().length / 2, 1)
: Math.max(cpus().length - 1, 1)

const options: TinypoolOptions = {
filename: workerPath,
// Disable this for now, for WebContainer capability
// https://github.com/vitest-dev/vitest/issues/93
// In future we could conditionally enable it based on the env
useAtomics: false,

maxThreads: ctx.config.maxThreads ?? threadsCount,
minThreads: ctx.config.minThreads ?? threadsCount,
}
if (ctx.config.maxThreads != null)
options.maxThreads = ctx.config.maxThreads
if (ctx.config.minThreads != null)
options.minThreads = ctx.config.minThreads
if (ctx.config.isolate) {
options.isolateWorkers = true
options.concurrentTasksPerWorker = 1
Expand Down

0 comments on commit 3df5d8b

Please sign in to comment.