-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Node crashes when building default theme - "JavaScript heap out of memory" #3362
Comments
I've identified the problem here: build.ts:109I have fixed it using a pooling mechanism. I will provide a PR shortly. |
I guess #3285 should fix this? |
I've read the code. It's the same issue, but I think I can provide a solution that is more efficient. In addition, I will try to make "thread count" available for user config. Here is a preview: (pool.ts is added to ../utils) /**
* Since this pool is not a thread pool, we can give it a "thread count"
* larger than the actual number of CPUs available.
* ---
* https://github.com/vuejs/vitepress/issues/3362
* This fix will defer the memory allocation of render tasks.
* ---
* By limiting the max number of dispatched promises, it allows NodeJS to
* reclaim memory associated to each promise, avoiding memory allocation
* failures when handling large volume of pages.
* ---
* Fixes: #3362
*/
const renderPageTaskPool = new Pool(64);
// Pool all rendering tasks
for (const page of ['404.md', ...siteConfig.pages])
renderPageTaskPool.add(() => renderPage(
render,
siteConfig,
siteConfig.rewrites.map[page] || page,
clientResult,
appChunk,
cssChunk,
assets,
pageToHashMap,
metadataScript,
additionalHeadTags
));
// Wait for all rendering tasks to finish
await renderPageTaskPool.drain(); Will you consider it if I file a PR? |
Yeah sure! |
Describe the bug
I am trying to convert X.org documentation to a VitePress site.
The volume of content is very large and I ended up generating a huge
sidar
object, that is about12,430
lines when formatted. The serializedsidebar
object is available here: sidebar.jsonThe vitepress dev server can handle it pretty well. But when I try to bundle it, the build command will stuck at "rendering pages", and then crash after a few minutes. I've attached the full crash log in "additional context".
Cause of the problem
I have verified the problem is introduced by the
sidebar
object because as soon as I exclude the sidebar object from the config object exported byconfig.mjs
, the problem went away.My thoughts
Although the sidebar object is huge, I do not think it is large enough to crash Node.js. I am assuming the sidebar component of the default theme ran into circular reference when parsing the sidebar.
In addition, I have ruled out the possibility of a circular reference in my exported
sidebar
object by usingJSON.parse(JSON.stringify(sidebar))
.Reproduction
1. Clone and initialize the project
2. Run "setup" to generate markdown source tree
Warning
This command takes a few minutes and will occupy all your CPUs
3. Now you can verify the project under dev server (should work fine):
npm run dev # You can look around and the sidebar should be rendered correctly
4. And reproduce the problem by building for distribution:
npm run build # Will crash
Expected behavior
Should build just fine, since dev server worked fine.
System Info
Additional context
Crash scene (command:
npm run build
)Validations
The text was updated successfully, but these errors were encountered: