Skip to content

Commit b7c613b

Browse files
authored
[code-infra] Allow controlling worker concurrency (#327)
1 parent e66280d commit b7c613b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/bundle-size-checker/src/cli.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { fetchSnapshot } from './fetchSnapshot.js';
1616
* @typedef {import('./sizeDiff.js').SizeSnapshot} SizeSnapshot
1717
*/
1818

19-
const MAX_CONCURRENCY = Math.min(8, os.cpus().length);
19+
// Default concurrency is set to the number of available CPU cores
20+
const DEFAULT_CONCURRENCY = os.availableParallelism();
2021

2122
const rootDir = process.cwd();
2223

@@ -56,7 +57,7 @@ function normalizeEntries(entries) {
5657
async function getWebpackSizes(args, config) {
5758
const worker = new Piscina({
5859
filename: new URL('./worker.js', import.meta.url).href,
59-
maxThreads: MAX_CONCURRENCY,
60+
maxThreads: args.concurrency || DEFAULT_CONCURRENCY,
6061
});
6162
// Clean and recreate the build directory
6263
const buildDir = path.join(rootDir, 'build');
@@ -108,14 +109,16 @@ async function getWebpackSizes(args, config) {
108109
* @param {CommandLineArgs} argv - Command line arguments
109110
*/
110111
async function run(argv) {
111-
const { analyze, accurateBundles, output, verbose, filter } = argv;
112+
const { output, concurrency } = argv;
112113

113114
const snapshotDestPath = output ? path.resolve(output) : path.join(rootDir, 'size-snapshot.json');
114115

115116
const config = await loadConfig(rootDir);
116117

117-
// Pass the filter patterns to getWebpackSizes if provided
118-
const webpackSizes = await getWebpackSizes({ analyze, accurateBundles, verbose, filter }, config);
118+
// eslint-disable-next-line no-console
119+
console.log(`Starting bundle size snapshot creation with ${concurrency} workers...`);
120+
121+
const webpackSizes = await getWebpackSizes(argv, config);
119122
const bundleSizes = Object.fromEntries(webpackSizes.sort((a, b) => a[0].localeCompare(b[0])));
120123

121124
// Ensure output directory exists
@@ -382,6 +385,12 @@ yargs(process.argv.slice(2))
382385
alias: 'F',
383386
describe: 'Filter entry points by glob pattern(s) applied to their IDs',
384387
type: 'array',
388+
})
389+
.option('concurrency', {
390+
alias: 'c',
391+
describe: 'Number of workers to use for parallel processing',
392+
type: 'number',
393+
default: DEFAULT_CONCURRENCY,
385394
});
386395
},
387396
handler: run,

packages/bundle-size-checker/src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ interface CommandLineArgs {
7373
output?: string;
7474
verbose?: boolean;
7575
filter?: string[];
76+
concurrency?: number;
7677
}
7778

7879
// Diff command argument types

0 commit comments

Comments
 (0)