From eebcb64ada190e08e1fefe3e56754e1ad7386704 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 17 Oct 2024 18:36:51 +0200 Subject: [PATCH 1/6] add head memory to perf logging --- packages/docusaurus-logger/src/logger.ts | 1 + packages/docusaurus-logger/src/perfLogger.ts | 63 ++++++++++++++++++-- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-logger/src/logger.ts b/packages/docusaurus-logger/src/logger.ts index e05f206168ae..096e4935a444 100644 --- a/packages/docusaurus-logger/src/logger.ts +++ b/packages/docusaurus-logger/src/logger.ts @@ -178,6 +178,7 @@ const logger = { red: (msg: string | number): string => chalk.red(msg), yellow: (msg: string | number): string => chalk.yellow(msg), green: (msg: string | number): string => chalk.green(msg), + cyan: (msg: string | number): string => chalk.cyan(msg), bold: (msg: string | number): string => chalk.bold(msg), dim: (msg: string | number): string => chalk.dim(msg), path, diff --git a/packages/docusaurus-logger/src/perfLogger.ts b/packages/docusaurus-logger/src/perfLogger.ts index b92319504a91..ceac6353b3f1 100644 --- a/packages/docusaurus-logger/src/perfLogger.ts +++ b/packages/docusaurus-logger/src/perfLogger.ts @@ -37,6 +37,11 @@ type PerfLoggerAPI = { ) => Promise; }; +type Memory = { + before: NodeJS.MemoryUsage; + after: NodeJS.MemoryUsage; +}; + function createPerfLogger(): PerfLoggerAPI { if (!PerfDebuggingEnabled) { const noop = () => {}; @@ -58,19 +63,56 @@ function createPerfLogger(): PerfLoggerAPI { } }; - const logDuration = (label: string, duration: number) => { + const formatMemory = (memory: Memory): string => { + const fmtHead = (bytes: number) => + logger.cyan(`${(bytes / 1000000).toFixed(0)}mb`); + return logger.dim( + `(${fmtHead(memory.before.heapUsed)} -> ${fmtHead( + memory.after.heapUsed, + )})`, + ); + }; + + const printPerfLog = ({ + label, + duration, + memory, + }: { + label: string; + duration: number; + memory: Memory; + }) => { if (duration < Thresholds.min) { return; } - console.log(`${PerfPrefix + label} - ${formatDuration(duration)}`); + console.log( + `${PerfPrefix + label} - ${formatDuration(duration)} - ${formatMemory( + memory, + )}`, + ); }; - const start: PerfLoggerAPI['start'] = (label) => performance.mark(label); + const start: PerfLoggerAPI['start'] = (label) => + performance.mark(label, { + detail: { + memoryUsage: process.memoryUsage(), + }, + }); const end: PerfLoggerAPI['end'] = (label) => { - const {duration} = performance.measure(label); + const { + duration, + detail: {memoryUsage}, + } = performance.measure(label); performance.clearMarks(label); - logDuration(applyParentPrefix(label), duration); + printPerfLog({ + label: applyParentPrefix(label), + duration, + memory: { + before: memoryUsage, + after: process.memoryUsage(), + }, + }); }; const log: PerfLoggerAPI['log'] = (label: string) => @@ -79,9 +121,18 @@ function createPerfLogger(): PerfLoggerAPI { const async: PerfLoggerAPI['async'] = async (label, asyncFn) => { const finalLabel = applyParentPrefix(label); const before = performance.now(); + const memoryBefore = process.memoryUsage(); const result = await ParentPrefix.run(finalLabel, () => asyncFn()); + const memoryAfter = process.memoryUsage(); const duration = performance.now() - before; - logDuration(finalLabel, duration); + printPerfLog({ + label: finalLabel, + duration, + memory: { + before: memoryBefore, + after: memoryAfter, + }, + }); return result; }; From 9a5eedc20705b1f62e65abbfd0ecbb6b53498977 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 17 Oct 2024 18:51:57 +0200 Subject: [PATCH 2/6] add max memory for Docusaurus site build CI --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 38dad22a5ba6..c6de54f3f885 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,6 +44,10 @@ jobs: run: yarn workspace @docusaurus/theme-common removeThemeInternalReexport - name: Docusaurus Build run: yarn build:website:fast + env: + # Our website should build even with limited memory + # See https://github.com/facebook/docusaurus/pull/10590 + NODE_OPTIONS: '--max-old-space-size=300' - name: Docusaurus site CSS order run: yarn workspace website test:css-order From 73965ed58288b9de65157380da10d804a53715b7 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 17 Oct 2024 18:57:00 +0200 Subject: [PATCH 3/6] add max memory for Docusaurus site build CI --- .github/workflows/tests-e2e.yml | 8 ++++++++ .github/workflows/tests.yml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 41a1eee2bb84..8e48321db5c9 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -63,6 +63,10 @@ jobs: E2E_TEST: true - name: Build test-website project run: yarn build + env: + # Our website should build even with limited memory + # See https://github.com/facebook/docusaurus/pull/10590 + NODE_OPTIONS: '--max-old-space-size=150' working-directory: ../test-website yarn-berry: @@ -129,6 +133,10 @@ jobs: - name: Build test-website project run: yarn build + env: + # Our website should build even with limited memory + # See https://github.com/facebook/docusaurus/pull/10590 + NODE_OPTIONS: '--max-old-space-size=150' working-directory: ../test-website npm: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c6de54f3f885..342a67eb35a7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,7 +47,7 @@ jobs: env: # Our website should build even with limited memory # See https://github.com/facebook/docusaurus/pull/10590 - NODE_OPTIONS: '--max-old-space-size=300' + NODE_OPTIONS: '--max-old-space-size=200' - name: Docusaurus site CSS order run: yarn workspace website test:css-order From 876453766207c61e323823eee34602264fcb7cd7 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 17 Oct 2024 20:42:41 +0200 Subject: [PATCH 4/6] add max memory for Docusaurus site build CI --- .github/workflows/tests-e2e.yml | 6 ++++-- .github/workflows/tests.yml | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 8e48321db5c9..3e887ec35b54 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -66,7 +66,8 @@ jobs: env: # Our website should build even with limited memory # See https://github.com/facebook/docusaurus/pull/10590 - NODE_OPTIONS: '--max-old-space-size=150' + NODE_OPTIONS: '--max-old-space-size=200' + DOCUSAURUS_PERF_LOGGER: 'true' working-directory: ../test-website yarn-berry: @@ -136,7 +137,8 @@ jobs: env: # Our website should build even with limited memory # See https://github.com/facebook/docusaurus/pull/10590 - NODE_OPTIONS: '--max-old-space-size=150' + NODE_OPTIONS: '--max-old-space-size=200' + DOCUSAURUS_PERF_LOGGER: 'true' working-directory: ../test-website npm: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 342a67eb35a7..145790cecd7a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,7 +47,8 @@ jobs: env: # Our website should build even with limited memory # See https://github.com/facebook/docusaurus/pull/10590 - NODE_OPTIONS: '--max-old-space-size=200' + NODE_OPTIONS: '--max-old-space-size=350' + DOCUSAURUS_PERF_LOGGER: 'true' - name: Docusaurus site CSS order run: yarn workspace website test:css-order From 97b0608f2e042b6a4f16dc0e5c34a3f9ca505e5e Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 17 Oct 2024 20:54:30 +0200 Subject: [PATCH 5/6] add max memory for Docusaurus site build CI --- .github/workflows/tests-e2e.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 3e887ec35b54..98248749567f 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -66,7 +66,7 @@ jobs: env: # Our website should build even with limited memory # See https://github.com/facebook/docusaurus/pull/10590 - NODE_OPTIONS: '--max-old-space-size=200' + NODE_OPTIONS: '--max-old-space-size=250' DOCUSAURUS_PERF_LOGGER: 'true' working-directory: ../test-website @@ -137,7 +137,7 @@ jobs: env: # Our website should build even with limited memory # See https://github.com/facebook/docusaurus/pull/10590 - NODE_OPTIONS: '--max-old-space-size=200' + NODE_OPTIONS: '--max-old-space-size=250' DOCUSAURUS_PERF_LOGGER: 'true' working-directory: ../test-website @@ -169,6 +169,11 @@ jobs: E2E_TEST: true - name: Build test-website project run: npm run build + env: + # Our website should build even with limited memory + # See https://github.com/facebook/docusaurus/pull/10590 + NODE_OPTIONS: '--max-old-space-size=250' + DOCUSAURUS_PERF_LOGGER: 'true' working-directory: ../test-website pnpm: @@ -202,4 +207,9 @@ jobs: E2E_TEST: true - name: Build test-website project run: pnpm run build + env: + # Our website should build even with limited memory + # See https://github.com/facebook/docusaurus/pull/10590 + NODE_OPTIONS: '--max-old-space-size=250' + DOCUSAURUS_PERF_LOGGER: 'true' working-directory: ../test-website From 1ad99f7a318dd36628ce765356277ff7b3b54196 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 17 Oct 2024 21:02:45 +0200 Subject: [PATCH 6/6] add max memory for Docusaurus site build CI --- .github/workflows/tests-e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 98248749567f..db3e5b25533b 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -137,7 +137,7 @@ jobs: env: # Our website should build even with limited memory # See https://github.com/facebook/docusaurus/pull/10590 - NODE_OPTIONS: '--max-old-space-size=250' + NODE_OPTIONS: '--max-old-space-size=300' DOCUSAURUS_PERF_LOGGER: 'true' working-directory: ../test-website