-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
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 esThe 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: