Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22
24
18 changes: 17 additions & 1 deletion bin/commands/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { loadAndParse } from '../utils.mjs';

const availableGenerators = Object.keys(publicGenerators);

// Half of available logical CPUs guarantees in general all physical CPUs are being used
// which in most scenarios is the best way to maximize performance
const optimalThreads = Math.floor(cpus().length / 2) + 1;

/**
* @typedef {Object} Options
* @property {Array<string>|string} input - Specifies the glob/path for input files.
Expand All @@ -26,6 +30,7 @@ const availableGenerators = Object.keys(publicGenerators);
* @property {string} typeMap - Specifies the path to the Node.js Type Map.
* @property {string} [gitRef] - Git ref/commit URL.
* @property {number} [threads] - Number of threads to allow.
* @property {number} [chunkSize] - Number of items to process per worker thread.
*/

/**
Expand Down Expand Up @@ -61,10 +66,20 @@ export default {
},
threads: {
flags: ['-p', '--threads <number>'],
desc: 'Number of worker threads to use',
prompt: {
type: 'text',
message: 'How many threads to allow',
initialValue: String(Math.max(cpus().length, 1)),
initialValue: String(Math.max(optimalThreads, 1)),
},
},
chunkSize: {
flags: ['--chunk-size <number>'],
desc: 'Number of items to process per worker thread (default: auto)',
prompt: {
type: 'text',
message: 'Items per worker thread',
initialValue: '10',
},
},
version: {
Expand Down Expand Up @@ -149,6 +164,7 @@ export default {
releases,
gitRef: opts.gitRef,
threads: parseInt(opts.threads, 10),
chunkSize: parseInt(opts.chunkSize, 10),
index,
typeMap,
});
Expand Down
Loading
Loading