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
fix: support compiling monorepo on single-core CPU machines #14720
Conversation
Gulpfile.mjs
Outdated
@@ -222,7 +223,8 @@ function getFiles(glob, { include, exclude }) { | |||
} | |||
|
|||
function createWorker(useWorker) { | |||
const numWorkers = require("os").cpus().length / 2 - 1; | |||
// jest-worker defaults | |||
const numWorkers = cpus().length - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to keep the / 2
(using all my cores except for one might slow things down, if I'm doing other tasks in parallel), we can use Math.ceil(require("os").cpus().length / 2 - 1)
. Also, if cpus().length
is 1 we probably want 1 worker and not 0 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If CPU length is 1 or 2 (for Intel CPU with hyper-threading), the numWorkers
is 0 so we don't spawn extra workers and run in the main process instead.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52421/ |
@@ -222,7 +223,7 @@ function getFiles(glob, { include, exclude }) { | |||
} | |||
|
|||
function createWorker(useWorker) { | |||
const numWorkers = require("os").cpus().length / 2 - 1; | |||
const numWorkers = Math.ceil(cpus().length / 2) - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cpus().length
can be 0
so this can give you a negative number.
Ref yarnpkg/berry#3090
Fixed building errors on single-core CPU machines, here we use the default value (CPU length - 1) for
numWorkers
. I mark the PR as internal because this issue does not affect end users.