Skip to content

Commit

Permalink
Only enable worker threads if there is more than 1 worker
Browse files Browse the repository at this point in the history
Multiple worker threads can cause problems when certain dependencies are
being used, see e.g. vercel#7894

This patch allows disabling of worker threads by setting
`config.experimental.cpus = 1`.

The benefit of spawning 1 worker thread, if there is any at all, should
very limited anyways, so the workload can just as well be processed in
the main thread.
  • Loading branch information
ctavan committed Oct 25, 2019
1 parent 0c42f78 commit 67d6902
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export default async function build(dir: string, conf = null): Promise<void> {

const staticCheckWorkers = new Worker(staticCheckWorker, {
numWorkers: config.experimental.cpus,
enableWorkerThreads: true,
enableWorkerThreads: config.experimental.cpus > 1,
})

const analysisBegin = process.hrtime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default class TaskRunner {

if (this.maxConcurrentWorkers > 1) {
this.workers = new Worker(worker, {
enableWorkerThreads: true,
numWorkers: this.maxConcurrentWorkers,
enableWorkerThreads: this.maxConcurrentWorkers > 1,
})
this.boundWorkers = options => this.workers.default(options)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default async function(
{
maxRetries: 0,
numWorkers: threads,
enableWorkerThreads: true,
enableWorkerThreads: threads > 1,
exposedMethods: ['default'],
}
) as any
Expand Down

0 comments on commit 67d6902

Please sign in to comment.