Skip to content

fix: support compiling monorepo on single-core CPU machines#14720

Merged
JLHwung merged 2 commits intobabel:mainfrom
JLHwung:use-jest-worker-defaults
Jul 4, 2022
Merged

fix: support compiling monorepo on single-core CPU machines#14720
JLHwung merged 2 commits intobabel:mainfrom
JLHwung:use-jest-worker-defaults

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented Jul 4, 2022

Q                       A
Fixed Issues? Fixes #14715
Patch: Bug Fix? Y
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

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.

@JLHwung JLHwung added the PR: Internal 🏠 A type of pull request used for our changelog categories label Jul 4, 2022
Gulpfile.mjs Outdated
function createWorker(useWorker) {
const numWorkers = require("os").cpus().length / 2 - 1;
// jest-worker defaults
const numWorkers = cpus().length - 1;
Copy link
Copy Markdown
Member

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 🤔

Copy link
Copy Markdown
Contributor Author

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.

@babel-bot
Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52421/

@nicolo-ribaudo nicolo-ribaudo changed the title fix: use jest-worker numWorkers defaults fix: support compiling monorepo on single-core CPU machines Jul 4, 2022
@JLHwung JLHwung merged commit d68be3f into babel:main Jul 4, 2022
@JLHwung JLHwung deleted the use-jest-worker-defaults branch July 4, 2022 14:32

function createWorker(useWorker) {
const numWorkers = require("os").cpus().length / 2 - 1;
const numWorkers = Math.ceil(cpus().length / 2) - 1;
Copy link
Copy Markdown
Contributor

@merceyz merceyz Jul 5, 2022

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

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal 🏠 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Build failure "RangeError: Invalid array length"

5 participants