fix: support compiling monorepo on single-core CPU machines#14720
Merged
JLHwung merged 2 commits intobabel:mainfrom Jul 4, 2022
Merged
fix: support compiling monorepo on single-core CPU machines#14720JLHwung merged 2 commits intobabel:mainfrom
JLHwung merged 2 commits intobabel:mainfrom
Conversation
Gulpfile.mjs
Outdated
| function createWorker(useWorker) { | ||
| const numWorkers = require("os").cpus().length / 2 - 1; | ||
| // jest-worker defaults | ||
| const numWorkers = cpus().length - 1; |
Member
There was a problem hiding this comment.
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 🤔
Contributor
Author
There was a problem hiding this comment.
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.
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52421/ |
nicolo-ribaudo
approved these changes
Jul 4, 2022
liuxingbaoyu
approved these changes
Jul 4, 2022
merceyz
reviewed
Jul 5, 2022
|
|
||
| function createWorker(useWorker) { | ||
| const numWorkers = require("os").cpus().length / 2 - 1; | ||
| const numWorkers = Math.ceil(cpus().length / 2) - 1; |
Contributor
There was a problem hiding this comment.
cpus().length can be 0 so this can give you a negative number.
Ref yarnpkg/berry#3090
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.