Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow using atomics to communicate between threads #2758

Merged
merged 2 commits into from Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.