diff --git a/.github/scripts/backend-js-footprint.mjs b/.github/scripts/backend-js-footprint.mjs index af6d92c3ee..3def41d554 100644 --- a/.github/scripts/backend-js-footprint.mjs +++ b/.github/scripts/backend-js-footprint.mjs @@ -42,10 +42,6 @@ function isInside(parent, child) { return rel === '' || (!rel.startsWith('..') && !rel.includes(`..${sep}`)); } -function normalizePath(filePath) { - return filePath.split(sep).join('/'); -} - function bytesToKiB(value) { return Math.round(value / 1024); } @@ -128,7 +124,7 @@ async function stopServer(serverProcess) { } function getPackageNameFromPath(filePath) { - const normalized = normalizePath(filePath); + const normalized = util.normalizePath(filePath); const marker = '/node_modules/'; const index = normalized.lastIndexOf(marker); if (index === -1) return null; @@ -248,7 +244,7 @@ function readFileMetrics(filePath) { const packageInfo = readPackageInfo(filePath); const metric = { path: filePath, - displayPath: normalizePath(relative(repoDir, filePath)), + displayPath: util.normalizePath(relative(repoDir, filePath)), sourceBytes: source.byteLength, gzipBytes: gzipSync(source).byteLength, ...astMetrics, diff --git a/.github/scripts/backend-memory-report.mts b/.github/scripts/backend-memory-report.mts index 2bd00bb27d..7d2ab1677c 100644 --- a/.github/scripts/backend-memory-report.mts +++ b/.github/scripts/backend-memory-report.mts @@ -106,10 +106,6 @@ function getSamplesByRound(report: MemoryReport) { return samplesByRound; } -function formatDeltaMemory(diffKiB: number) { - return util.formatColoredDelta(formatMemoryMb(Math.abs(diffKiB)), diffKiB); -} - function pairedDeltaSummary(base: MemoryReport, head: MemoryReport, phase: typeof memoryReportPhases[number]['key'], metric: typeof metrics[number]) { const baseSamplesByRound = getSamplesByRound(base); const headSamplesByRound = getSamplesByRound(head); @@ -141,6 +137,10 @@ function renderMainTableForPhase(base: MemoryReport, head: MemoryReport, phase: '| --- | ---: | ---: | ---: | ---: | ---: | ---: |', ]; + function formatDeltaMemory(diffKiB: number) { + return util.formatColoredDelta(formatMemoryMb(Math.abs(diffKiB)), diffKiB); + } + for (const metric of metrics) { const baseValue = getMemoryValue(base, phase, metric); const headValue = getMemoryValue(head, phase, metric); @@ -157,14 +157,6 @@ function renderMainTableForPhase(base: MemoryReport, head: MemoryReport, phase: return lines.join('\n'); } -function getDiffPercent(base: MemoryReport, head: MemoryReport, phase: typeof memoryReportPhases[number]['key'], metric: typeof metrics[number]) { - const baseValue = getMemoryValue(base, phase, metric); - const headValue = getMemoryValue(head, phase, metric); - if (baseValue == null || headValue == null || baseValue <= 0) return null; - - return ((headValue - baseValue) * 100) / baseValue; -} - /* function measurementSummary(base, head) { const baseCount = base?.sampleCount; @@ -199,17 +191,6 @@ function escapeCsvValue(value: string) { return `"${String(value).replaceAll('"', '""')}"`; } -function formatSankeyPercentValue(value: number) { - const rounded = Math.round(value * 100) / 100; - if (rounded === 0 && value > 0) return '0.01'; - if (Number.isInteger(rounded)) return String(rounded); - return rounded.toFixed(2).replace(/0+$/, '').replace(/\.$/, ''); -} - -function formatHeapSnapshotSankeyChildLabel(label: string) { - return String(label).replace(/^[^:]+:\s*/, ''); -} - function renderHeapSnapshotSankey(report: MemoryReport, phase: typeof memoryReportPhases[number]['key'], title: string) { const total = getHeapSnapshotCategoryValue(report, phase, 'Total'); if (total == null || total <= 0) return null; @@ -223,6 +204,17 @@ function renderHeapSnapshotSankey(report: MemoryReport, phase: typeof memoryRepo .toSorted((a, b) => b[1] - a[1]); } + function formatHeapSnapshotSankeyChildLabel(label: string) { + return String(label).replace(/^[^:]+:\s*/, ''); + } + + function formatSankeyPercentValue(value: number) { + const rounded = Math.round(value * 100) / 100; + if (rounded === 0 && value > 0) return '0.01'; + if (Number.isInteger(rounded)) return String(rounded); + return rounded.toFixed(2).replace(/0+$/, '').replace(/\.$/, ''); + } + const categories = util.heapSnapshotCategories .filter(category => category !== 'Total') .map(category => { @@ -637,6 +629,14 @@ function getWarningMetric(base: MemoryReport, head: MemoryReport) { return null; } +function getDiffPercent(base: MemoryReport, head: MemoryReport, phase: typeof memoryReportPhases[number]['key'], metric: typeof metrics[number]) { + const baseValue = getMemoryValue(base, phase, metric); + const headValue = getMemoryValue(head, phase, metric); + if (baseValue == null || headValue == null || baseValue <= 0) return null; + + return ((headValue - baseValue) * 100) / baseValue; +} + function isBeyondSampleNoise(base: MemoryReport, head: MemoryReport, phase: typeof memoryReportPhases[number]['key'], metric: typeof metrics[number]) { const baseValue = getMemoryValue(base, phase, metric); const headValue = getMemoryValue(head, phase, metric);