Skip to content
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

Docusaurus leaks memory on i18n site builds #10944

Open
slorber opened this issue Feb 21, 2025 · 0 comments
Open

Docusaurus leaks memory on i18n site builds #10944

slorber opened this issue Feb 21, 2025 · 0 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: performance Related to bundle size or perf optimization

Comments

@slorber
Copy link
Collaborator

slorber commented Feb 21, 2025

When building a Docusaurus site with multiple locales, the memory keeps increasing.

What happens, in pseudo-code:

async function buildSite() {
  await buildLocale("en"); // +20mb
  await buildLocale("fr"); // +20mb
  await buildLocale("ja"); // +20mb
  await buildLocale("es"); // +20mb
}

This can be seen on our website, but also our init template (much smaller leak though).

In #10599 we solved an important leak, but we still leak memory and should investigate so that it's possible to build a Docusaurus site in thousands of locales without having to increase the heap size.


Repro

yarn install

yarn clear:website

NODE_OPTIONS="--max-old-space-size=250 --expose-gc" DOCUSAURUS_PERF_LOGGER=true yarn build:website:fast --locale en --locale fr --locale ja --locale es

The logs show memory increasing after each locale despite calling globalThis.gc?.() before measures.

[PERF] Build > en - 20.90 seconds! - (58mb -> 144mb)
[PERF] Build > fr - 30.94 seconds! - (144mb -> 162mb)
[PERF] Build > ja - 32.49 seconds! - (162mb -> 180mb)
[PERF] Build > es - 33.00 seconds! - (180mb -> 197mb)
[PERF] Build - 117.36 seconds! - (58mb -> 197mb)

Heap dumps

Heap dumps can be taken after each locale build with little edits in packages/docusaurus/src/commands/build/build.ts

async function runBuildLocaleTask(params: BuildLocaleParams) {
  await buildLocale(params);

  globalThis.gc?.();
  require('v8').writeHeapSnapshot(
    `docusaurus-heap-${Date.now()}-${params.locale}.heapsnapshot`,
  );
}

Access upon request: https://drive.google.com/drive/folders/11JrI_sgw_uwtGBAza52AEyVpiH33Qyq8?usp=sharing


Edit: from this discussion, we can assume that the memory leak grows with the number of MDX docs:
#9211 (reply in thread)


Edit: these articles presents interesting ways to run memory leak tests:

@slorber slorber added bug An error in the Docusaurus core causing instability or issues with its execution domain: performance Related to bundle size or perf optimization labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: performance Related to bundle size or perf optimization
Projects
None yet
Development

No branches or pull requests

1 participant