Skip to content

Commit

Permalink
feat: allow using atomics to communicate between threads (#2758)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jan 27, 2023
1 parent a9878c5 commit 3679cf2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
10 changes: 10 additions & 0 deletions docs/config/index.md
Expand Up @@ -489,6 +489,16 @@ Maximum number of threads. You can also use `VITEST_MAX_THREADS` environment var

Minimum number of threads. You can also use `VITEST_MIN_THREADS` environment variable.

### useAtomics

- **Type:** `boolean`
- **Default:** `false`
- **Version:** Since Vitest 0.28.3

Use Atomics to synchronize threads.

This can improve performance in some cases, but might cause segfault in older Node versions.

### testTimeout

- **Type:** `number`
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/package.json
Expand Up @@ -133,7 +133,7 @@
"std-env": "^3.3.1",
"strip-literal": "^1.0.0",
"tinybench": "^2.3.1",
"tinypool": "^0.3.0",
"tinypool": "^0.3.1",
"tinyspy": "^1.0.2",
"vite": "^3.0.0 || ^4.0.0",
"vite-node": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/pool.ts
Expand Up @@ -43,7 +43,7 @@ export function createPool(ctx: Vitest): WorkerPool {
filename: workerPath,
// TODO: investigate further
// It seems atomics introduced V8 Fatal Error https://github.com/vitest-dev/vitest/issues/1191
useAtomics: false,
useAtomics: ctx.config.useAtomics ?? false,

maxThreads,
minThreads,
Expand Down Expand Up @@ -141,7 +141,7 @@ export function createPool(ctx: Vitest): WorkerPool {
// node before 16.17 has a bug that causes FATAL ERROR because of the race condition
const nodeVersion = Number(process.version.match(/v(\d+)\.(\d+)/)?.[0].slice(1))
if (nodeVersion >= 16.17)
await Promise.all(pool.threads.map(w => w.terminate()))
await pool.destroy()
},
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/vitest/src/types/config.ts
Expand Up @@ -235,6 +235,15 @@ export interface InlineConfig {
*/
minThreads?: number

/**
* Use Atomics to synchronize threads
*
* This can improve performance in some cases, but might cause segfault in older Node versions.
*
* @default false
*/
useAtomics?: boolean

/**
* Default timeout of a test in milliseconds
*
Expand Down
20 changes: 11 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3679cf2

Please sign in to comment.