perf: reduce build memory and time #1156
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1156"
general
weight: 0.35
araujogui
Description
Building the Node.js docs peaks at 3.6–3.8GB of memory, while a single page only needs ~100MB. Node core only builds the HTML docs on machines with more than 5GiB of memory, and silently skips them otherwise. That's what happens on its
ubuntu-slimdoc CI, whose docs artifact has no HTML at all.This PR brings the peak down to 1.7–2.1GB, and the build time to about a third:
jsx-ast. The docs use about ten languages. Each one is now registered the first time code in it is highlighted, with the languages it embeds, which takes highlighting from ~17s of CPU to ~4s, and the themes go to Shiki by name, so it stops parsing them again for every block. Code highlights the same whatever a thread highlighted before: fences in a Markdown block are registered with it, and a grammar injecting into others (ts-tags) only does so in its own blocks.@node-core/rehype-shikiis updated to 1.5.1, whose plugin only imports every grammar when it isn't given a highlighter (nodejs/nodejs.org#9212).hast-util-to-html, and types and signatures are embedded as they're highlighted, beforerehype-rawwould parse each of their tokens again. Each thread also highlights a type only once (of the ~20,000 types the docs highlight, 741 differ).all.htmlrenders in the worker pool. It was rendered and minified on the main thread, after every other page, holding the whole site there (~1GB).all.html) and is never returned, so every thread rendering pages kept it until it ended, and minifying took a fifth of the build's CPU. On Node 24, the worker holding that memory collected garbage on nearly every allocation, which took the build from ~8s to ~52s. In exchange, the 741 pages were 5.9% smaller on disk, but only 3.2% smaller gzipped and 2.1% with brotli, which is how they're served: Cloudflare, Vercel, Netlify and GitHub Pages compress HTML on their own, and so do doc-kit.nodejs.org and nodejs.org. Sominifynow defaults tofalse, and the minifier only loads when it's enabled;docs/publishing.mdshows how to serve the output compressed. Scripts and styles stay minified, unlessvite.build.minifysays otherwise.jsx-astworkers' heaps (~800MB) are gone while the main thread bundles the site, which is when the build peaked.--max-old-space-sizereplaces the limit, to raise it.@actions/coreandundicion every thread (237 modules, 19MB and ~80ms per thread, down to 10 modules, 3MB and 7ms).How a build runs
The main thread schedules the generators, holds their results and bundles the site with Vite. The rest of the work goes to a pool of worker threads, which end once idle:
With
threads: 1, the main thread runs the chunks itself.Validation
node --run test(747 tests) passes at every commit, andnode --run format:checkandnode --run lintpass.mainonce both are minified withmain's minifier and parsed as HTML (hast-util-to-htmlspells a few characters in code differently than Preact did, such as<for<), on thewebtarget (71 pages), on Node core's config (741) and onlegacy-html(69), except the C++ code blocks ofaddons,embeddingandn-api(andall.html, which holds them), whose grammar now comes from core's ownshiki(4.4.3) instead of the one@node-core/rehype-shiki1.5.0 pinned (4.3.1).--max-old-space-size, which limits every isolate, the Node core build passes at 384MB (not at 320MB), wheremainneeds 768MB.Benchmarks
main→ this branch, building Node core's docs with its config (legacy-json-all+section-pages) unless noted. Medians of 3 interleaved runs on an M4 Pro; peak memory is the physical footprint of every process in the build.| Build | Peak memory | Duration | CPU time |
| --- | --- | --- | --- |
| Node 26, 4 threads | 3,626MB → 1,654MB (-54%) | 22.5s → 7.7s | 83.7s → 32.5s |
| Node 26, 1 thread | 3,787MB → 2,017MB (-47%) | 49.3s → 15.0s | 60.7s → 20.3s |
| Node 24, 4 threads | 3,823MB → 2,098MB (-45%) | 23.8s → 7.7s | 90.7s → 34.1s |
|
webtarget, Node 26 | 3,335MB → 1,598MB (-52%) | 17.8s → 5.8s | 58.0s → 23.7s |With one thread, the main thread does all the work, and the workers' heap limit doesn't apply. Node's
--max-old-space-size=768brings that build to 1.47GB in about the same time.Related Issues
Refs: #815
Refs: https://github.com/nodejs/node/pull/62045
Check List
node --run testand all tests passed.node --run format:check&node --run lint.