From 431526ecbc19705755cfca905b2c9a80d7ef4653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Mon, 6 Jan 2025 14:13:14 +0100 Subject: [PATCH] fix: perflogger mark detail bug (#10818) --- packages/docusaurus-logger/src/perfLogger.ts | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus-logger/src/perfLogger.ts b/packages/docusaurus-logger/src/perfLogger.ts index 77b911dd94..7f9575c18c 100644 --- a/packages/docusaurus-logger/src/perfLogger.ts +++ b/packages/docusaurus-logger/src/perfLogger.ts @@ -114,12 +114,24 @@ function createPerfLogger(): PerfLoggerAPI { }, }); - const end: PerfLoggerAPI['end'] = (label) => { - const { - duration, - detail: {memoryUsage}, - } = performance.measure(label); + const readMark = (label: string) => { + const startMark = performance.getEntriesByName( + label, + 'mark', + )?.[0] as PerformanceMark; + if (!startMark) { + throw new Error(`No performance start mark for label=${label}`); + } performance.clearMarks(label); + return startMark; + }; + + const end: PerfLoggerAPI['end'] = (label) => { + const startMark = readMark(label); + const duration = performance.now() - startMark.startTime; + const { + detail: {memoryUsage}, + } = startMark; printPerfLog({ label: applyParentPrefix(label), duration,