Skip to content

perf: use up to 6 threads by default - #1243

Open
ovflowd wants to merge 1 commit into
refactor/html-allfrom
perf/six-threads
Open

ovflowd wants to merge 1 commit into
refactor/html-allfrom
perf/six-threads

Conversation

@ovflowd

@ovflowd ovflowd commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Description

This PR makes builds use up to 6 threads by default, instead of 4. It's the last part of the stack that splits #1205. On top of the stack, the site build goes from 8.09s at 4 threads to 7.09s at 6, against 9.82s for main at 4.

8 threads were no faster than 6 for the site build on Node.js 24, and used ~15% more memory; I haven't re-measured them on Node.js 26. Machines with fewer CPUs, like CI's 4, are unaffected, and --threads still sets any count.

Why it's built this way

Isn't the stack's speedup just the extra threads? No. At the same thread count, #1242 is 18% faster than main at 4 threads and 17% faster at 6. Going from 4 to 6 threads is a separate gain, and main gets about the same from it (-13%, against -12% on #1242). So 6 threads would have paid off before the stack too. What kept the default at 4 is memory, since each worker holds a heap of its own.

What does it cost? On #1242 the two extra threads add 655MB to the site build's peak, against 552MB on main in the same run, and 393MB to legacy. Each at its own default, measured in one round before the manifest fix in #1241, this branch against main is -22% time and +52% memory on the site build, and -10% / +28% on legacy. Most of that memory comes back with #1235 and #1236: with them, against main before #1237, each at its own default, the site build is 29% faster for 24% more memory (measured before the manifest fix in #1241, which moves the 6-thread peak by ~3%). --threads 4 gets the old behaviour back, each worker's heap is still capped at 512MB, and -p 1 isn't touched.

Why does the bundler get 6 too? Since #1179, Vite's native pools (rolldown and lightningcss) follow doc-kit's thread count through ROLLDOWN_WORKER_THREADS and RAYON_NUM_THREADS. Otherwise they'd start a thread per CPU, 32 on this machine. This PR only moves the number they follow, and the numbers below include the bundler at 6. Keeping it at 4 while the workers go to 6 would be a second knob I haven't measured. Either variable set in the environment still wins.

What about CI? The default is Math.min(cpus().length, 6). CI's ubuntu-latest runners have 4 CPUs, so CI keeps 4 workers and a 4-thread bundler, and the time and RSS in its comparison comment stay comparable with main's. riscv64 stays at 1, and #1253 runs with threads: 1, so it doesn't exercise this change.

Benchmarks

Full Node.js docs on Node.js 26, 32 CPUs, medians of 5 interleaved runs, peak RSS summed over the process tree. The site build is orama-db, json, llms-txt and section-pages, plus html-all from #1242 on (on main, html still builds all.html itself). Each row is one build at -p 4 and -p 6, so the columns differ only by the thread count, which is all this PR changes:

-p 4 -p 6
Site, #1242 8.09s, 2159MB 7.09s (-12%), 2814MB (+30%)
Site, main 9.82s, 1728MB 8.56s (-13%), 2280MB (+32%)
Legacy, #1242 4.31s, 1551MB 3.92s (-9%), 1944MB (+25%)
Site, with #1235 and #1236 7.59s, 1840MB 6.76s (-11%), 2187MB (+19%)

The first two rows are one run, with the manifest fix that #1241 now includes. Legacy doesn't go through jsx-ast, so the fix doesn't touch it; that row and the last one come from earlier runs, from before the fix.

Everything merged, after the review fixes

The stack with #1235 and #1236 on top, before the review fixes (tests trimmed, createSignal inlined, discardResults, html-all's dead fallback gone) and after, against main. One round, medians of 5 interleaved runs (3 at -p 1). This machine ran slower overall in this round, so compare the columns with each other, not with the tables above:

Build Threads main Before After
site 4 14.15s, 1737MB -21% time, +3% memory -21%, +2%
site 6 12.77s, 2157MB -27%, +9% -27%, +5%
site 1 24.00s, 1979MB -9%, -16% -8%, -10%
legacy 4 6.68s, 1571MB -8%, -11% -13%, -13%
legacy 6 6.29s, 1913MB -13%, -6% -12%, -6%
legacy 1 9.64s, 1239MB -6%, -11% -9%, -5%

The fixes don't move it. The -p 1 memory gap between before and after is GC timing: per-run peaks overlap (site 1651-1783MB before, 1592-1792MB after).

Validation

The benchmarks above, plus -p 1 with --max-old-space-size=512, 3 runs each: the site build passed all 11 at ~1000MB peak RSS (main hit V8's out-of-memory abort in 1 of 8 runs), and legacy passed all 3 at 877MB.

Related Issues

Refs: #1205, and nodejs/nodejs.org#9253, which caches tokens for both themes and makes the site build faster still.

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format:check & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api-docs-tooling Ready Ready Preview Nov 11, 2026 12:07am UTC

Request Review

@ovflowd
ovflowd added this pull request to stack #1244 November 3, 2026 19:34
@ovflowd ovflowd mentioned this pull request Nov 3, 2026
4 tasks done
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.55%. Comparing base (78217c5) to head (589914f).

Additional details and impacted files
@@                Coverage Diff                 @@
##           refactor/html-all    #1243   +/-   ##
==================================================
  Coverage              94.55%   94.55%           
==================================================
  Files                    297      297           
  Lines                  31220    31221    +1     
  Branches                3187     3187           
==================================================
+ Hits                   29521    29522    +1     
  Misses                  1677     1677           
  Partials                  22       22           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 589914f 2026-11-11T00:07:46.193Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ c283664 2026-11-10T20:53:54.619Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ d6f41cc 2026-11-09T13:26:28.458Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ c4b0dc4 2026-11-09T11:04:29.752Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 5624386 2026-11-09T10:38:13.644Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ fd18bd4 2026-11-09T02:27:09.786Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ cf7e6c8 2026-11-06T19:44:55.815Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ c97afb1 2026-11-06T19:32:39.022Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 7e715a5 2026-11-06T13:39:03.963Z View logs ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 4d830af 2026-11-04T18:26:01.974Z View logs ↗

View all previews: View all previews ↗

@ovflowd
ovflowd marked this pull request as ready for review November 3, 2026 20:39
@ovflowd
ovflowd requested a review from a team as a code owner November 3, 2026 20:39
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 <noreply@anthropic.com>
Assisted-by: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview – api-docs-tooling — 589914f5 Deployed Nov 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants