defaultSlots

tcmts.cli.budget.defaultSlots · #gaq7mp2d · term · runs anywhere

How many slots a machine with cpus logical cores, performance of them performance cores (on a chip with two kinds; else all are) and memory bytes has. What takes one (a suite: tcm, the TypeScript checker, Vite, a browser; checking; a build) keeps about a core busy as it goes, so a slot for each performance core and one for every three efficiency cores, and 2 GB of memory each; never fewer than 2.

export function defaultSlots(cpus: number, performance: number, memory: number): number {
  const p = Math.min(Math.max(performance, 0), cpus) || cpus;
  const byCores = p + Math.floor((cpus - p) / 3);
  const byMemory = Math.floor(memory / 2 ** 31);
  return Math.max(2, Math.min(byCores, byMemory));
}

used by