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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gulpfile.mjs
@@ -1,5 +1,6 @@
import path from "path";
import fs from "fs";
import { cpus } from "os";
import { createRequire } from "module";
import { fileURLToPath } from "url";
import plumber from "gulp-plumber";
Expand Down Expand Up @@ -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

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

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.

if (numWorkers === 0 || !useWorker) {
return require("./babel-worker.cjs");
}
Expand Down