Repository navigation
perf: keep memory use down at low thread counts #1179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+275
−32
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
890022e
perf: keep memory use down at low thread counts
ovflowd fb523fa
perf(react): size the bundler's thread pools and allocator
ovflowd 1368640
meta: add changeset for the memory changes
ovflowd 95cef19
perf: only copy jsx-ast's input on the main thread
ovflowd fe6db04
perf: raise the worker young generation cap to 64MB
ovflowd c6ce951
perf: raise the worker young generation cap to 96MB
ovflowd 30c2deb
refactor: rename WORKER_YOUNG_GENERATION_SIZE to WORKER_GEN_SIZE
ovflowd fbe8747
fix(legacy-html): copy its input on the main thread
ovflowd aaaaa20
test: cover the memory changes
ovflowd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@doc-kit/core': patch | ||
| '@doc-kit/generator-react': patch | ||
| '@node-core/doc-kit-legacy': patch | ||
| --- | ||
|
|
||
| Builds use less memory, most of all with few threads: each worker's young generation is limited to 96MB, a single thread processes one chunk at a time and lets go of the pages' code before rendering them, and Vite's native bundler gets as many threads as doc-kit and returns the memory it frees. On the Node.js API docs, `--threads 1` now builds with Node.js's `--max-old-space-size=512`, and no longer crashes when `legacy-html` is built alongside other targets. |
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
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
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
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
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
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
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
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
56 changes: 56 additions & 0 deletions
56
packages/node-legacy/src/legacy-html/__tests__/generate.test.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
|
|
||
| import { loadGenerator } from '@doc-kit/core/generators/loader.mjs'; | ||
| import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs'; | ||
| import { loadMarkdownPlugins } from '@doc-kit/core/utils/markdown/plugins.mjs'; | ||
|
|
||
| import { processChunk } from '../generate.mjs'; | ||
|
|
||
| await loadMarkdownPlugins( | ||
| await loadGenerator(import.meta.resolve('../index.mjs')) | ||
| ); | ||
|
|
||
| const createEntry = (api, name) => { | ||
| const heading = { | ||
| type: 'heading', | ||
| depth: 1, | ||
| children: [{ type: 'text', value: name }], | ||
| data: { name, text: name, slug: api, type: 'module' }, | ||
| }; | ||
|
|
||
| return { | ||
| api, | ||
| path: `/${api}`, | ||
| heading, | ||
| stability: null, | ||
| content: { | ||
| type: 'root', | ||
| children: [ | ||
| heading, | ||
| { | ||
| type: 'paragraph', | ||
| children: [{ type: 'text', value: `${name} body` }], | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| describe('legacy-html processChunk', () => { | ||
| it('does not change its input on the main thread', async () => { | ||
| await setConfig({ target: ['legacy-html'] }); | ||
|
|
||
| const fs = createEntry('fs', 'File system'); | ||
| const before = structuredClone(fs); | ||
|
|
||
| const [page] = await processChunk( | ||
| [{ head: fs, nodes: [fs], headNodes: [fs] }], | ||
| [0], | ||
| '<a class="nav-fs" href="fs.html">File system</a>' | ||
| ); | ||
|
|
||
| assert.match(page.content, /File system body/); | ||
| assert.deepEqual(fs, before); | ||
| }); | ||
| }); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { afterEach, describe, it, mock } from 'node:test'; | ||
|
|
||
| import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs'; | ||
|
|
||
| mock.module('../vite.mjs', { | ||
| namedExports: { createViteBundler: () => 'vite' }, | ||
| }); | ||
|
|
||
| const { resolveBundler } = await import('../index.mjs'); | ||
|
|
||
| const VARIABLES = [ | ||
| 'ROLLDOWN_WORKER_THREADS', | ||
| 'RAYON_NUM_THREADS', | ||
| 'MIMALLOC_PURGE_DELAY', | ||
| 'MIMALLOC_ALLOW_THP', | ||
| ]; | ||
|
|
||
| const original = Object.fromEntries( | ||
| VARIABLES.map(name => [name, process.env[name]]) | ||
| ); | ||
|
|
||
| afterEach(() => { | ||
| for (const name of VARIABLES) { | ||
| if (original[name] === undefined) { | ||
| delete process.env[name]; | ||
| } else { | ||
| process.env[name] = original[name]; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| describe('resolveBundler', () => { | ||
| it("sizes the bundler's thread pools and allocator before loading it", async () => { | ||
| await setConfig({ target: ['html'], threads: 3 }); | ||
|
|
||
| for (const name of VARIABLES) { | ||
| delete process.env[name]; | ||
| } | ||
|
|
||
| assert.equal(await resolveBundler(), 'vite'); | ||
| assert.equal(process.env.ROLLDOWN_WORKER_THREADS, '3'); | ||
| assert.equal(process.env.RAYON_NUM_THREADS, '3'); | ||
| assert.equal(process.env.MIMALLOC_PURGE_DELAY, '0'); | ||
| assert.equal(process.env.MIMALLOC_ALLOW_THP, '0'); | ||
| }); | ||
|
|
||
| it('keeps what the environment already sets', async () => { | ||
| await setConfig({ target: ['html'], threads: 3 }); | ||
|
|
||
| process.env.ROLLDOWN_WORKER_THREADS = '8'; | ||
| process.env.MIMALLOC_PURGE_DELAY = '250'; | ||
|
|
||
| await resolveBundler(); | ||
|
|
||
| assert.equal(process.env.ROLLDOWN_WORKER_THREADS, '8'); | ||
| assert.equal(process.env.MIMALLOC_PURGE_DELAY, '250'); | ||
| }); | ||
|
|
||
| it('leaves the environment alone for a custom bundler', async () => { | ||
| for (const name of VARIABLES) { | ||
| delete process.env[name]; | ||
| } | ||
|
|
||
| const bundler = {}; | ||
|
|
||
| assert.equal(await resolveBundler(bundler), bundler); | ||
|
|
||
| for (const name of VARIABLES) { | ||
| assert.equal(process.env[name], undefined); | ||
| } | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.