From 301ee5ed15daafb1721fd28d912edf52d489ae12 Mon Sep 17 00:00:00 2001 From: Claudio Wunder Date: Tue, 3 Nov 2026 19:06:22 +0100 Subject: [PATCH 1/3] perf: use up to 6 threads by default With generators streaming into each other, more threads now pay off, so DEFAULT_MAX_THREADS goes from 4 to 6. On the Node.js API docs the site build is ~15% faster at 6 threads than at 4, for ~20% more memory; 8 threads were no faster than 6 and used ~15% more. Machines with fewer CPUs, like CI's 4, are unaffected, and --threads still sets any count. Assisted-by: Claude Opus 5.5 Assisted-by: Claude Sonnet 5.5 --- .changeset/six-threads.md | 5 +++++ docs/configuration.md | 2 +- packages/core/src/threading/constants.mjs | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changeset/six-threads.md diff --git a/.changeset/six-threads.md b/.changeset/six-threads.md new file mode 100644 index 000000000..adc09d4c7 --- /dev/null +++ b/.changeset/six-threads.md @@ -0,0 +1,5 @@ +--- +'@doc-kit/core': minor +--- + +Builds use up to 6 threads by default, instead of 4: with generators streaming into each other, more threads now pay off. On the Node.js API docs, the site build is ~15% faster at 6 threads than at 4, for ~20% more memory, while 8 threads were no faster than 6. `--threads` still sets any count. diff --git a/docs/configuration.md b/docs/configuration.md index 8d14a398e..7b52af6db 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -180,7 +180,7 @@ These sit at the top level, next to `target` and `global`: - `threads` {number} Worker threads to process with, at least 1. With `1`, everything runs on the main thread. **Default:** the number of CPUs, up to - 4 (`1` on riscv64). + 6 (`1` on riscv64). - `chunkSize` {number} Items each worker processes per task, at least 1. **Default:** `10`. - `discardResults` {boolean} Keep none of the requested generators' results, diff --git a/packages/core/src/threading/constants.mjs b/packages/core/src/threading/constants.mjs index 21f5178a2..6e2e08bfe 100644 --- a/packages/core/src/threading/constants.mjs +++ b/packages/core/src/threading/constants.mjs @@ -3,9 +3,10 @@ /** * The default `threads` ceiling. Each worker holds a heap of its own, with the * libraries and the pages it is working on, so past a few threads memory, not - * CPU, is what runs out. `--threads` raises it. + * CPU, is what runs out: on the Node.js docs, 8 threads were no faster than 6, + * for ~15% more memory. `--threads` raises it. */ -export const DEFAULT_MAX_THREADS = 4; +export const DEFAULT_MAX_THREADS = 6; /** * The heap size limit of each worker thread (V8's old space), in MB. V8 lets a From a5b491fa54fd435759ac23b1458a11de48b27cdf Mon Sep 17 00:00:00 2001 From: Claudio Wunder Date: Fri, 27 Nov 2026 21:13:44 +0100 Subject: [PATCH 2/3] fix: count the CPUs a build may use for its default threads os.cpus() counts every CPU of the host, so in a container limited to 2 CPUs the default went from 4 workers to 6. os.availableParallelism() honours CPU affinity and quotas, and gives the same count elsewhere. The CLI docs said the default was up to 4 threads. Assisted-by: Claude Opus 5.5 --- .changeset/six-threads.md | 2 +- docs/cli.md | 2 +- packages/core/src/utils/configuration/index.mjs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.changeset/six-threads.md b/.changeset/six-threads.md index adc09d4c7..4fcd6fc12 100644 --- a/.changeset/six-threads.md +++ b/.changeset/six-threads.md @@ -2,4 +2,4 @@ '@doc-kit/core': minor --- -Builds use up to 6 threads by default, instead of 4: with generators streaming into each other, more threads now pay off. On the Node.js API docs, the site build is ~15% faster at 6 threads than at 4, for ~20% more memory, while 8 threads were no faster than 6. `--threads` still sets any count. +Builds use up to 6 threads by default, instead of 4: with generators streaming into each other, more threads now pay off. On the Node.js API docs, the site build is ~15% faster at 6 threads than at 4, for ~20% more memory, while 8 threads were no faster than 6. The CPUs are counted with `os.availableParallelism()`, so a container or a CPU affinity limit lowers the default. `--threads` still sets any count. diff --git a/docs/cli.md b/docs/cli.md index 23579c232..36b76e280 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -59,7 +59,7 @@ parentheses. - `--minify` {boolean} Minify the output (`global.minify`). **Default:** `false`. - `-p, --threads ` {number} Worker threads to use, at least 1 (`threads`). - **Default:** the number of CPUs, up to 4. + **Default:** the number of CPUs, up to 6 (`1` on riscv64). - `--chunk-size ` {number} Items each worker processes per task, at least 1 (`chunkSize`). **Default:** `10`. diff --git a/packages/core/src/utils/configuration/index.mjs b/packages/core/src/utils/configuration/index.mjs index 9690e0bea..e66d3ed42 100644 --- a/packages/core/src/utils/configuration/index.mjs +++ b/packages/core/src/utils/configuration/index.mjs @@ -1,5 +1,5 @@ import { readFileSync } from 'node:fs'; -import { cpus } from 'node:os'; +import { availableParallelism } from 'node:os'; import { fileURLToPath } from 'node:url'; import { isMainThread } from 'node:worker_threads'; @@ -80,7 +80,7 @@ export const getDefaultConfig = (generators, config) => threads: process.arch === 'riscv64' ? 1 - : Math.min(cpus().length, DEFAULT_MAX_THREADS), + : Math.min(availableParallelism(), DEFAULT_MAX_THREADS), chunkSize: DEFAULT_CHUNK_SIZE, }) ); From 292469bdf6aa2960e3700dfa7e7bbeddc80ded03 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sat, 28 Nov 2026 16:53:06 -0500 Subject: [PATCH 3/3] Apply suggestion from @avivkeller Signed-off-by: Aviv Keller --- .changeset/six-threads.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/six-threads.md b/.changeset/six-threads.md index 4fcd6fc12..22b873f89 100644 --- a/.changeset/six-threads.md +++ b/.changeset/six-threads.md @@ -1,5 +1,5 @@ --- -'@doc-kit/core': minor +'@doc-kit/core': patch --- Builds use up to 6 threads by default, instead of 4: with generators streaming into each other, more threads now pay off. On the Node.js API docs, the site build is ~15% faster at 6 threads than at 4, for ~20% more memory, while 8 threads were no faster than 6. The CPUs are counted with `os.availableParallelism()`, so a container or a CPU affinity limit lowers the default. `--threads` still sets any count.