Repository navigation
perf: keep memory use down at low thread counts - #1179
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1179 +/- ##
==========================================
+ Coverage 93.42% 93.63% +0.21%
==========================================
Files 286 288 +2
Lines 28502 28738 +236
Branches 2870 2901 +31
==========================================
+ Hits 26628 26909 +281
+ Misses 1852 1807 -45
Partials 22 22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
ovflowd
marked this pull request as ready for review
October 26, 2026 12:21
This was referenced Oct 26, 2026
4 tasks
- Cap each worker's young generation at 32MB. V8 sizes it as if each worker had the whole machine, so it was over half of a worker's heap. - With one thread, process chunks one at a time, on a copy of their input as a worker gets. All chunks used to start at once, holding all their work together, and `jsx-ast` changed the metadata `legacy-json` reads, which only worked because `legacy-json` happened to finish first. - Let go of the pages' code once `html` compiled their programs: the generator and its caller both held it until every page was rendered. - Move `DEFAULT_MAX_THREADS` to the threading constants. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Vite's native bundler started a thread per CPU in rolldown's runtime and in the Rayon pool it shares with lightningcss, each holding memory of its own, and its allocator (mimalloc) kept what it freed: it only purges on its next call past a delay, which never comes once bundling ends, and with transparent huge pages it only returns whole free 2MB pages. On the Node.js docs that left ~800MB resident through rendering. The pools now get the threads doc-kit was given (`ROLLDOWN_WORKER_THREADS`, `RAYON_NUM_THREADS`; `TOKIO_WORKER_THREADS` and `ROLLDOWN_MAX_BLOCKING_THREADS` made no difference), and mimalloc returns memory as it's freed (`MIMALLOC_PURGE_DELAY=0`, `MIMALLOC_ALLOW_THP=0`). They're read when the bundler loads, so they're set just before it is, unless the environment already sets them. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Copying every chunk's input with one thread cost ~2.5s of a ~24s build, while only `jsx-ast` needs it: building a page changes its entries, and on the main thread those are the metadata other generators read. It now copies its own input there, and workers keep using theirs as is. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
At 32MB, workers collected their young generation often enough to cost 6-8% at 4 threads. 64MB keeps most of the memory saved (26-34% at 4 threads) within 1-2.5% of `main`'s build time. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
On 4 CPUs, like CI's runners, 64MB and 96MB keep the same memory (19% less across json, legacy-json, legacy-html, orama-db and web) and 96MB was marginally faster. It's also what V8 gives a worker with a 512MB old generation on Node.js 26, so the cap only changes Node.js 24. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Building a page splices the heading out of its entries' content and replaces the stability nodes, and on the main thread those entries are the metadata other generators read. With one thread, building `legacy-html` with other targets crashed (`Cannot read properties of undefined (reading 'tagName')`), on `main` too. It now works on a copy there, as it already does in a worker. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
- With one thread, chunks are processed one at a time, in order. - Workers get both the old and young generation limits. - jsx-ast and legacy-html leave their input unchanged on the main thread. - resolveBundler sets the bundler's thread and allocator variables from `threads`, keeps any already set, and leaves a custom bundler alone. Each fails against `main`. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
avivkeller
approved these changes
Oct 30, 2026
Merged
ovflowd
added a commit
that referenced
this pull request
Nov 6, 2026
This site now builds in 2.4 s and the Node.js v26.12.1 API docs in 9.1 s, on Node.js 26.13. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
ovflowd
added a commit
that referenced
this pull request
Nov 9, 2026
This site now builds in 2.4 s and the Node.js v26.12.1 API docs in 9.1 s, on Node.js 26.13. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 9, 2026
ovflowd
added a commit
that referenced
this pull request
Nov 17, 2026
This site now builds in 2.4 s and the Node.js v26.12.1 API docs in 9.1 s, on Node.js 26.13. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
ovflowd
added a commit
that referenced
this pull request
Nov 17, 2026
* docs: rewrite and restructure the documentation Rewrites every page, package README and generator README for clarity and accuracy against the code, and splits the docs into guides, which teach a task with one running example, and reference pages, which list every option. Guides link to the reference instead of repeating it. - `index.md` becomes `introduction.md`, and a new guide covers documenting TypeScript and JSDoc with `@doc-kit/typedoc`. - Every generator page follows one layout: what it makes, what it reads and writes, usage, options, then details. - The specification gains a reading guide, a table of its constructs and examples for every directive, and resolves rules it stated as both MUST and SHOULD. - Code examples whose Markdown bullets the formatter rewrote (the changelog, `index.md` and `llms.txt` samples) are plain text again, so they show what doc-kit actually reads and writes. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * feat(www): redesign doc-kit.nodejs.org Gives doc-kit's own site a theme of its own, built entirely through the html generator's public extension points (theme slots, components, stylesheets, a template and rehype plugins), so the site doubles as an example of customizing doc-kit. - A home page that shows what doc-kit does: an isometric hero, the sources and outputs of one kittens module, the worker pool building a site, benchmarks and a getting-started path. Its canvases are islands that respect reduced motion. - A neutral palette over `@node-core/ui-components`, with light and dark themes, a cat logo, Inter, and styled search and theme menus. - Five isometric illustrations in the guides, inlined as SVG so they follow the color scheme, each on the one page it explains. - The sidebar groups guides, reference, generators and packages; the build script also takes the site's own pages from `www/pages`, and leaves out the legacy-format generators and the generators documented on another generator's page. Redirects send their old URLs to the sections that now cover them. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(react): replay the press that hydrates an island Islands that hydrate on interaction, such as code tabs and copy buttons, start loading their component on pointerover, focusin or touchstart. The click or tap that follows lands before the component exists, so it did nothing and had to be repeated. The runtime now holds an interaction island's presses until it is hydrated, then dispatches them again, each once the innermost island around it is ready. The site's redesign surfaced this on every code block. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * refactor(www): skip comments instead of stripping them when inlining diagrams The diagram parser removed the XML declaration and comments with one regex replace before tokenizing, which CodeQL flags as incomplete multi-character sanitization: a crafted input could re-form `<!--` after the replace. Each one already arrives as its own token, so the parser now skips those tokens instead. The inlined diagrams are byte-for-byte the same. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * refactor(react): keep the press events with the other UI constants Moves `PRESS_EVENTS` into `ui/constants.mjs`, and says why only a held click is prevented: preventing a pointerdown would also suppress the mouse events that follow it, which are held too, and preventing a mousedown would stop focus and text selection. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * chore(www): make the site its own workspace package The site's dependencies (Inter, Preact and the html generator its theme builds on) move from the root package.json into a private `@doc-kit/www` package, so the root only holds the repo's own tooling again. Preact still resolves to the one copy the html generator uses. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * chore(www): add the source of the social preview image `www/og/og.html` is the card behind `www/public/og.png`, and `node --run og` renders it again with Playwright, in the site's own fonts, so the image can change with the site. It reproduces the current image pixel for pixel. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * feat(www): make the benchmarks reproducible The home page and the introduction quote build times that were measured by hand. `node --run benchmark` in `www/` now measures them: it builds this site and a Node.js release's API docs, each target on its own and all of them in one run, from a clean output every time, and writes the medians, the page and word counts, the JavaScript the home page loads up front, the machine and the commit to `www/theme/benchmarks.json`, which `data.mjs` reads. The numbers are re-measured with it: five runs each, for this site's 40 pages and the Node.js v26.12.1 API docs. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * docs: give every generator its own page again The site builds every generator's page again, rather than folding json-all, json-simple and llms-txt-full into their parent pages and leaving the legacy-format package out. Their READMEs get their content back, in the layout every generator page shares, and the legacy package's pages are rewritten to match, checked against its code. The overview lists them all, while the sidebar keeps to the main generators. The page globs also merge into one, and the redirects for these pages are gone, as they exist again. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * feat(www): write the home page in MDX on doc-kit's own code blocks The home page's words and code samples now live in `www/pages/index.mdx` instead of a JSX component, so they're edited like any other page. Its code samples are fenced blocks, highlighted by doc-kit and shown in its own code boxes and tabs, with their copy buttons, which replaces the theme's own highlighter, copy button, code box, install tabs and output tabs. What MDX can't express stays in thin components: the two canvas animations, the sections' layout, and the hand-drawn previews and card art. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * docs: link to one place instead of repeating it Each topic now lives on one page and the others link to it: CLI flags in cli.md, global options and URL templates in configuration.md, type links in writing-docs.md, the typedoc and html READMEs as the references their guides point to. Generator READMEs lose the shared boilerplate, and the internal stages are trimmed down. Snippets use `npx @doc-kit/cli` and are back to what they did on main. The spec is back to main's, flags use the typed-list form doc-kit parses, and statements that documented bugs as behaviour are gone. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(react): scope the heading layout and mark the selected code tab The heading row layout matched any div holding a heading inside <main>, so pages that render their own headings there got it too. API entry headings now carry a `heading` class, and the layout applies to that. With the neutral brand palette, the selected code tab was no brighter than the others, and in dark mode it was dimmer. It now takes the text color, and tabs wrap on narrow screens instead of scrolling out of view. The default template also gets a canonical link, built from `pageURL`, and `theme-color` for both schemes. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * refactor(www): drop the workarounds doc-kit no longer needs The home and 404 pages render a real <main> now that doc-kit's heading layout only applies to API entries, and the code tab and canonical link overrides are gone with doc-kit handling both. The script marking the platform's shortcut key and the last input type is gone too, with the CSS that read it: the search button's label and the theme menu's focus ring come from ui-components, so their fixes go there. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * feat(www): build the all page and take more from the configuration The all page is built again, and `@node-core/doc-kit-legacy` is back in the sidebar. The home page's components are every export of its module, its count of generators is taken from the repository at build time, and the footer lists the sidebar's pages instead of its own copy of them. On the home page, the hand-drawn site and search previews are gone, leaving the real outputs, the install tabs show up once, and the steps end with `doc-kit preview` now that it has shipped. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * docs(react): shorten the comment on held presses Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * refactor: move the benchmark to scripts/ and slim it down `scripts/benchmark.mjs` replaces `www/benchmark.mjs`, without the word counts and the copy of the site's sources, and builds every Markdown file in Node.js's `doc/api` instead of leaving `quic.md` out by hand. The home page's data no longer spells out numbers, and the numbers are refreshed. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * docs: make the diagrams self-contained and play them once Each SVG now carries its own styles, light and dark colors, timing, and the subset of Inter and IBM Plex Mono it uses, so it renders the same as a plain image on the site and on GitHub. Images follow the page's color scheme, so they also follow the site's theme switch. The site's rehype plugin that inlined them and the stylesheets that styled them are gone. The motion plays once and holds on the finished picture, which is also what reduced motion shows, instead of looping. dependent.svg no longer shows connectors from section-pages before it has landed, the chips in entry-anatomy.svg sit inside the editor so no leader crosses its edge, and chip labels get more room at their ends. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * feat(www): draw the home page's animations as SVGs The hero and the pipeline are exported SVGs now, with a narrower drawing of each for phones, and the canvas engine that drew them at runtime, with its two islands, is gone. They're drawn from the same build simulation and layout the canvas used, so they show the same run, and like the guides' diagrams they carry their own styles and fonts and follow the color scheme. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * refactor(www): keep the home page's main landmark on a div ui-components styles everything in a <main> as an article's prose: link colors, heading sizes and spacing, beyond the heading layout doc-kit now scopes to API entries. The home and 404 pages lay out their own content, so they mark it with `role="main"` rather than undo all of it. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * feat(www): polish Kit's head A domed brow between the ears instead of a flat one, softer ear tips, fuller cheeks and a rounder jaw and nose, in the mark, the favicon, the app icon, the hero and the social card. The social card lists only the inputs doc-kit reads itself. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * chore(www): format the social card's source Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(www): bring back the site and search previews Without them, the outputs' three code blocks sat next to each other, so doc-kit grouped them into a second row of tabs inside the first one and left the other two empty. The site preview now shows `options` as the real page does, without a `?`. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * docs: format the guides with oxfmt 0.74 Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(react): replay the press that starts an island loading An island with `interaction: true` starts loading on its first click, from is-land's listener on the island. `holdPresses` attached its listeners in the microtasks after that, too late for the click, so the first click on a button, or Enter or Space on it, did nothing. The runtime now records each press as it starts dispatching, and `holdPresses` also holds the one still being dispatched inside the island, which is the one that started it loading. An e2e spec presses a button that hydrates on its first click with Enter, Space and the mouse. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * docs: measure the benchmarks again now that #1179 has landed This site now builds in 2.4 s and the Node.js v26.12.1 API docs in 9.1 s, on Node.js 26.13. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> * test: add versioned pageURL tests for canonical function * fix(react): link the release line and the index's directory as canonical With Node.js's `pageURL`, `{baseURL}/latest-{version}/api{path}.html`, the canonical link of a page in 26.13.0 pointed at `latest-v26.13.x`, which doesn't exist: `getVersionFromSemVer` keeps a non-zero minor for the version selector's release lines. `{version}` is now the major's release line, `v26.x`, as `pageURL` documents. The index was always linked as `{baseURL}/`, ignoring `pageURL`. It now goes through `pageURL` like any other page, and a trailing `index` or `index.html` is trimmed to its directory, so Node.js's index is `latest-v26.x/api/` and this site's stays `/`. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: bmuenzenmeyer <brian.muenzenmeyer@gmail.com>
|
npm install --save-dev @doc-kit/cli doc-kit-rss |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR keeps doc-kit's memory use down, most of all at low thread counts, where
-p 1couldn't build the Node.js API docs under--max-old-space-size=512:WORKER_GEN_SIZE, passed asresourceLimits.maxYoungGenerationSizeMb). With a 512MB old generation, V8 gives a worker 192MB of young generation on Node.js 24 and 96MB on Node.js 26, so the cap only changes Node.js 24. Node.js's--max-semi-space-sizestill replaces it.-p 1, every chunk used to start at once, so all their work was held together. Chunks now run one after another.jsx-astandlegacy-htmlrewrites its entries' content, and on the main thread those are the metadata other generators read. A worker already gets its own copy, so they only copy there. With one thread, buildinglegacy-htmlwith other targets crashed onmain(Cannot read properties of undefined (reading 'tagName')), andlegacy-jsononly worked because it happened to finish beforejsx-ast. Copying every generator's input instead cost ~2.5s at-p 1.htmlcompiled the page programs, both it and the scheduler still held every page's code until the last page was rendered.buildAllPagenow runs insidebuildPrograms,generate()clears its input, andgenerators.mjsreturnsgenerate()instead of awaiting it.ROLLDOWN_WORKER_THREADSandRAYON_NUM_THREADS(documented by rolldown;TOKIO_WORKER_THREADSandROLLDOWN_MAX_BLOCKING_THREADSmade no difference), and mimalloc returns memory as it's freed (MIMALLOC_PURGE_DELAY=0,MIMALLOC_ALLOW_THP=0). mimalloc only purges on its next call past the delay, which never comes once bundling ends, so a shorter delay like 250ms doesn't help. These are read when the bundler loads, so they're set just before it is, unless the environment already sets them.DEFAULT_MAX_THREADSmoves to the threading constants, next toWORKER_HEAP_SIZE.V8 flags (
--optimize-for-size,--memory-saver-mode,--heap-growing-percent,--max-semi-space-sizeand Node.js 26's memory pool flags) were measured too and left out: they were slower or saved nothing on top of the above.Validation
node --run test(754/754),node --run lintandnode --run format:checkare clean. New tests cover each change and fail againstmain: one chunk at a time with a single thread, both worker generation limits,jsx-astandlegacy-htmlleaving their input unchanged on the main thread, andresolveBundlersetting the bundler's variables (keeping any already set).The output is the same as
main. On a fullwebbuild with section pages, with asset hashes normalized, only 3 of 918 files differ (two chunks andsitemap.xml), the same 3 that differ between twomainruns.all.jsonandorama-db.jsononly differ in order, which already varies betweenmainruns (orama's index changes size with insertion order, hence the -84B in CI). A-p 1build oflegacy-html,legacy-jsonandwebtogether matches the-p 4one file for file.CI's command and default threads, Node.js 24, pinned to 4 CPUs like CI's runners, medians of 4 runs:
mainlegacy-htmljsonorama-dblegacy-jsonwebA regular
webbuild (all CPUs, default threads), 4 runs:main-p 1with--max-old-space-size=512finishes 6/6 on this PR (1071–1181MB peak RSS on Node.js 24 and 26), whilemainfinished 0/3 on Node.js 26 and 1/3 on Node.js 24.CI's comparison comment pits a single run against an older
mainrun, so its timings swing a lot; pinned to 4 CPUs locally, the difference stays within ~0–5%.Related Issues
Follows #1156.
Check List
node --run testand all tests passed.node --run format:check&node --run lint.