mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-07-25 14:24:58 +02:00
chore(dev): tweak some workflows
This commit is contained in:
67
.github/scripts/frontend-js-size.mts
vendored
67
.github/scripts/frontend-js-size.mts
vendored
@@ -476,67 +476,6 @@ function renderFrontendBundleReport(before: ReturnType<typeof collectVisualizerR
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
const visualizerTreemapLimit = 50;
|
||||
|
||||
function mermaidTreemapLabel(value: string) {
|
||||
const label = String(value)
|
||||
.replaceAll('\\', '/')
|
||||
.replaceAll('"', "'")
|
||||
.replaceAll('`', "'")
|
||||
.replaceAll('\r', ' ')
|
||||
.replaceAll('\n', ' ')
|
||||
.trim();
|
||||
return label === '' ? '(unknown)' : label;
|
||||
}
|
||||
|
||||
function mermaidTreemapModuleLabel(id: string) {
|
||||
const normalizedId = String(id).replaceAll('\\', '/');
|
||||
const filePath = normalizedId.split(/[?#]/, 1)[0];
|
||||
const fileName = path.posix.basename(filePath);
|
||||
return mermaidTreemapLabel(fileName || normalizedId);
|
||||
}
|
||||
|
||||
function renderVisualizerTreemap(label: string, report: ReturnType<typeof collectVisualizerReport>) {
|
||||
const rows = report.hotModules
|
||||
.filter((row) => row.renderedLength > 0)
|
||||
.slice(0, visualizerTreemapLimit);
|
||||
const topRendered = rows.reduce((sum, row) => sum + row.renderedLength, 0);
|
||||
const otherRendered = Math.max(0, report.metrics.renderedLength - topRendered);
|
||||
const lines = [
|
||||
'```mermaid',
|
||||
`%%{init: ${JSON.stringify({
|
||||
treemap: {
|
||||
diagramPadding: 0,
|
||||
padding: 0,
|
||||
nodeHeight: 70,
|
||||
},
|
||||
})}}%%`,
|
||||
'treemap-beta',
|
||||
`"${mermaidTreemapLabel(label)}"`,
|
||||
];
|
||||
|
||||
for (const row of rows) {
|
||||
lines.push(` "${mermaidTreemapModuleLabel(row.id)}": ${Math.round(row.renderedLength)}`);
|
||||
}
|
||||
if (otherRendered > 0) {
|
||||
lines.push(` "Other": ${Math.round(otherRendered)}`);
|
||||
}
|
||||
|
||||
lines.push('```');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function renderVisualizerTreemapDetails(label: string, report: ReturnType<typeof collectVisualizerReport>, open = false) {
|
||||
return [
|
||||
`<details${open ? ' open' : ''}>`,
|
||||
`<summary>${label} rendered size treemap (top ${visualizerTreemapLimit} + Other)</summary>`,
|
||||
'',
|
||||
renderVisualizerTreemap(label, report),
|
||||
'',
|
||||
'</details>',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const [beforeDir, afterDir, beforeStatsFile, afterStatsFile, outFile] = args;
|
||||
const before = await collectReport(beforeDir);
|
||||
@@ -545,7 +484,7 @@ const beforeStats = JSON.parse(await fs.readFile(beforeStatsFile, 'utf8')) as Vi
|
||||
const afterStats = JSON.parse(await fs.readFile(afterStatsFile, 'utf8')) as VisualizerReport;
|
||||
const beforeVisualizerReport = collectVisualizerReport(beforeStats);
|
||||
const afterVisualizerReport = collectVisualizerReport(afterStats);
|
||||
const visualizerArtifactLink = `[Open detailed HTML](${process.env.FRONTEND_BUNDLE_REPORT_ARTIFACT_URL})`;
|
||||
const visualizerArtifactLink = `[Open treemap HTML](${process.env.FRONTEND_BUNDLE_REPORT_ARTIFACT_URL})`;
|
||||
|
||||
const body = [
|
||||
marker,
|
||||
@@ -558,10 +497,6 @@ const body = [
|
||||
'',
|
||||
renderFrontendBundleReport(beforeVisualizerReport, afterVisualizerReport),
|
||||
'',
|
||||
renderVisualizerTreemapDetails('Before', beforeVisualizerReport),
|
||||
'',
|
||||
renderVisualizerTreemapDetails('After', afterVisualizerReport),
|
||||
'',
|
||||
visualizerArtifactLink,
|
||||
].join('\n');
|
||||
|
||||
|
||||
30
.github/scripts/heap-snapshot-util.mts
vendored
30
.github/scripts/heap-snapshot-util.mts
vendored
@@ -55,13 +55,7 @@ export type HeapSnapshotReport = {
|
||||
};
|
||||
|
||||
function getHeapSnapshotCategoryValue(report: HeapSnapshotReport, category: typeof heapSnapshotCategories[number]) {
|
||||
const value = report.summary.categories[category];
|
||||
return Number.isFinite(value) ? value : null;
|
||||
}
|
||||
|
||||
function getHeapSnapshotCategoryValueFromSample(sample: HeapSnapshotReport['samples'][number], category: typeof heapSnapshotCategories[number]) {
|
||||
const value = sample.data.categories[category];
|
||||
return Number.isFinite(value) ? value : null;
|
||||
return report.summary.categories[category];
|
||||
}
|
||||
|
||||
export function renderHeapSnapshotTable(base: HeapSnapshotReport, head: HeapSnapshotReport) {
|
||||
@@ -72,17 +66,9 @@ export function renderHeapSnapshotTable(base: HeapSnapshotReport, head: HeapSnap
|
||||
const baseTotal = getHeapSnapshotCategoryValue(base, 'Total');
|
||||
const headTotal = getHeapSnapshotCategoryValue(head, 'Total');
|
||||
|
||||
function formatHeapSnapshotCategoryLabel(category: typeof heapSnapshotCategories[number], baseValue: number, headValue: number, baseTotal: number, headTotal: number) {
|
||||
return `**${category}**`;
|
||||
//if (category === 'Total') return `**${category}**`;
|
||||
//const basePercent = util.formatPercent((baseValue * 100) / baseTotal);
|
||||
//const headPercent = util.formatPercent((headValue * 100) / headTotal);
|
||||
//return `**${category}**<br>${basePercent} → ${headPercent}`;
|
||||
}
|
||||
|
||||
function getHeapSnapshotSampleSpread(report: HeapSnapshotReport, category: typeof heapSnapshotCategories[number]) {
|
||||
const values = report.samples
|
||||
.map(sample => getHeapSnapshotCategoryValueFromSample(sample, category))
|
||||
.map(sample => sample.data.categories[category])
|
||||
.filter(value => Number.isFinite(value)) as number[];
|
||||
if (values.length < 2) throw new Error(`Not enough samples for category ${category}`);
|
||||
|
||||
@@ -93,18 +79,20 @@ export function renderHeapSnapshotTable(base: HeapSnapshotReport, head: HeapSnap
|
||||
for (const category of heapSnapshotCategories) {
|
||||
const baseValue = getHeapSnapshotCategoryValue(base, category);
|
||||
const headValue = getHeapSnapshotCategoryValue(head, category);
|
||||
if (baseValue == null || headValue == null) continue;
|
||||
|
||||
const baseSpread = getHeapSnapshotSampleSpread(base, category);
|
||||
const headSpread = getHeapSnapshotSampleSpread(head, category);
|
||||
const summary = util.pairedDeltaSummary(base.samples, head.samples, (sample) => getHeapSnapshotCategoryValueFromSample(sample, category));
|
||||
const summary = util.pairedDeltaSummary(base.samples, head.samples, (sample) => sample.data.categories[category]);
|
||||
const percent = summary.median * 100 / baseValue;
|
||||
const deltaMedian = category === 'Total' ? `${util.formatDeltaBytes(summary.median)}<br>${util.formatDeltaPercent(percent).replaceAll('\\%', '\\\\%')}` : util.formatDeltaBytes(summary.median);
|
||||
const baseText = category === 'Total' ? `${util.formatBytes(baseValue)} <br> ± ${util.formatBytes(baseSpread)}` : util.formatBytes(baseValue);
|
||||
const headText = category === 'Total' ? `${util.formatBytes(headValue)} <br> ± ${util.formatBytes(headSpread)}` : util.formatBytes(headValue);
|
||||
const categoryLabel = formatHeapSnapshotCategoryLabel(category, baseValue, headValue, baseTotal, headTotal);
|
||||
const basePercent = util.formatPercent((baseValue * 100) / baseTotal);
|
||||
const headPercent = util.formatPercent((headValue * 100) / headTotal);
|
||||
const metricText = category === 'Total'
|
||||
? `$\\color{${heapSnapshotCategoriesColors[category]}}{\\rule{8pt}{8pt}}$ **${category}**`
|
||||
: `<details><summary>$\\color{${heapSnapshotCategoriesColors[category]}}{\\rule{8pt}{8pt}}$ **${category}**</summary>${basePercent} → ${headPercent}</details>`;
|
||||
|
||||
lines.push(`| $\\color{${heapSnapshotCategoriesColors[category]}}{\\rule{8pt}{8pt}}$ ${categoryLabel} | ${baseText} | ${headText} | ${deltaMedian} | ${util.formatBytes(summary.mad)} | ${util.formatDeltaBytes(summary.min)} | ${util.formatDeltaBytes(summary.max)} |`);
|
||||
lines.push(`| ${metricText} | ${baseText} | ${headText} | ${deltaMedian} | ${util.formatBytes(summary.mad)} | ${util.formatDeltaBytes(summary.min)} | ${util.formatDeltaBytes(summary.max)} |`);
|
||||
if (category === 'Total') {
|
||||
lines.push('| | | | | | | |');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user