histoire
Version:
A fast story book powered by Vite
19 lines (18 loc) • 812 B
JavaScript
/**
* Default dev worker count. Workers spend most of the first story waiting for
* the main thread to transform the app graph (vite-node `fetchModule`), and
* each one evaluates that whole graph: with a Nuxt app, 4 workers collect as
* fast as 16 with a third less CPU.
*/
const DEV_DEFAULT_THREADS = 4;
/**
* Number of story collection workers.
* @param mode Dev keeps half the cores for the dev server and browser; builds use all but one.
* @param cpuCount Available cores.
* @param maxThreads `collectMaxThreads` from the config.
*/
export function getCollectThreadCount(mode, cpuCount, maxThreads) {
if (mode === 'dev')
return Math.max(Math.min(maxThreads ?? DEV_DEFAULT_THREADS, Math.floor(cpuCount / 2)), 1);
return Math.max(Math.min(maxThreads ?? cpuCount, cpuCount - 1), 1);
}