Skip to content

Commit 4498cb2

Browse files
authored
perf(fmt): cap default worker count at eight (#149)
1 parent ab2e0c3 commit 4498cb2

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎packages/rstack/src/fmt/workerPool.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ interface FmtWorkerPool {
1414
terminate: () => Promise<void>;
1515
}
1616

17+
/**
18+
* Caps the default worker count at 8 because formatter throughput can
19+
* plateau before all CPU cores are occupied, while additional workers increase
20+
* scheduling and memory pressure.
21+
*/
1722
const getFmtWorkerCount = (fileCount: number, maxWorkers?: number): number =>
18-
Math.min(fileCount, maxWorkers ?? Math.max(1, availableParallelism() - 1));
23+
Math.min(fileCount, maxWorkers ?? Math.min(8, Math.max(1, availableParallelism() - 1)));
1924

2025
const getFmtWorkerUrl = (): URL => {
2126
// Source tests run after build and exercise the same worker artifact as the CLI.
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import { availableParallelism } from 'node:os';
21
import { expect, test } from 'rstack/test';
32
import { getFmtWorkerCount } from '../../src/fmt/workerPool.ts';
43

5-
test('uses one fewer worker than the available parallelism by default', () => {
6-
const defaultWorkerCount = Math.max(1, availableParallelism() - 1);
7-
8-
expect(getFmtWorkerCount(defaultWorkerCount + 1)).toBe(defaultWorkerCount);
9-
});
10-
114
test.each([
125
[4, 1, 1],
136
[4, 2, 2],
147
[2, 4, 2],
8+
[12, 10, 10],
159
])('uses %s files and %s configured workers as %s workers', (files, workers, expected) => {
1610
expect(getFmtWorkerCount(files, workers)).toBe(expected);
1711
});

0 commit comments

Comments
 (0)