Skip to content

Commit 3679cf2

Browse files
authoredJan 27, 2023
feat: allow using atomics to communicate between threads (#2758)
1 parent a9878c5 commit 3679cf2

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed
 

‎docs/config/index.md

+10
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,16 @@ Maximum number of threads. You can also use `VITEST_MAX_THREADS` environment var
489489

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

492+
### useAtomics
493+
494+
- **Type:** `boolean`
495+
- **Default:** `false`
496+
- **Version:** Since Vitest 0.28.3
497+
498+
Use Atomics to synchronize threads.
499+
500+
This can improve performance in some cases, but might cause segfault in older Node versions.
501+
492502
### testTimeout
493503

494504
- **Type:** `number`

‎packages/vitest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"std-env": "^3.3.1",
134134
"strip-literal": "^1.0.0",
135135
"tinybench": "^2.3.1",
136-
"tinypool": "^0.3.0",
136+
"tinypool": "^0.3.1",
137137
"tinyspy": "^1.0.2",
138138
"vite": "^3.0.0 || ^4.0.0",
139139
"vite-node": "workspace:*",

‎packages/vitest/src/node/pool.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function createPool(ctx: Vitest): WorkerPool {
4343
filename: workerPath,
4444
// TODO: investigate further
4545
// It seems atomics introduced V8 Fatal Error https://github.com/vitest-dev/vitest/issues/1191
46-
useAtomics: false,
46+
useAtomics: ctx.config.useAtomics ?? false,
4747

4848
maxThreads,
4949
minThreads,
@@ -141,7 +141,7 @@ export function createPool(ctx: Vitest): WorkerPool {
141141
// node before 16.17 has a bug that causes FATAL ERROR because of the race condition
142142
const nodeVersion = Number(process.version.match(/v(\d+)\.(\d+)/)?.[0].slice(1))
143143
if (nodeVersion >= 16.17)
144-
await Promise.all(pool.threads.map(w => w.terminate()))
144+
await pool.destroy()
145145
},
146146
}
147147
}

‎packages/vitest/src/types/config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ export interface InlineConfig {
235235
*/
236236
minThreads?: number
237237

238+
/**
239+
* Use Atomics to synchronize threads
240+
*
241+
* This can improve performance in some cases, but might cause segfault in older Node versions.
242+
*
243+
* @default false
244+
*/
245+
useAtomics?: boolean
246+
238247
/**
239248
* Default timeout of a test in milliseconds
240249
*

‎pnpm-lock.yaml

+11-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.