Skip to content
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

Merged
merged 2 commits into from Jul 4, 2022

Conversation

JLHwung
Copy link
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
@@ -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;
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo Jul 4, 2022

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
Contributor Author

@JLHwung JLHwung Jul 4, 2022

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
Collaborator

babel-bot commented Jul 4, 2022

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
35 checks passed
@JLHwung JLHwung deleted the use-jest-worker-defaults branch Jul 4, 2022
@@ -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;
Copy link
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