mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
feat: log slow pages in red (#11507)
* fix: log slow pages in red * apply feedback * chore: update based on feedback * Update .changeset/spotty-rice-shake.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
This commit is contained in:
parent
2cf770d759
commit
a62345fd18
2 changed files with 17 additions and 2 deletions
7
.changeset/spotty-rice-shake.md
Normal file
7
.changeset/spotty-rice-shake.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
'astro': minor
|
||||
---
|
||||
|
||||
Adds color-coding to the console output during the build to highlight slow pages.
|
||||
|
||||
Pages that take more than 500 milliseconds to render will have their build time logged in red. This change can help you discover pages of your site that are not performant and may need attention.
|
|
@ -1,7 +1,7 @@
|
|||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { bgGreen, black, blue, bold, dim, green, magenta } from 'kleur/colors';
|
||||
import { bgGreen, black, blue, bold, dim, green, magenta, red } from 'kleur/colors';
|
||||
import PQueue from 'p-queue';
|
||||
import type { OutputAsset, OutputChunk } from 'rollup';
|
||||
import type {
|
||||
|
@ -192,6 +192,8 @@ export async function generatePages(options: StaticBuildOptions, internals: Buil
|
|||
await runHookBuildGenerated({ config, logger });
|
||||
}
|
||||
|
||||
const THRESHOLD_SLOW_RENDER_TIME_MS = 500;
|
||||
|
||||
async function generatePage(
|
||||
pageData: PageBuildData,
|
||||
ssrEntry: SinglePageBuiltModule,
|
||||
|
@ -244,7 +246,13 @@ async function generatePage(
|
|||
const timeEnd = performance.now();
|
||||
const timeChange = getTimeStat(prevTimeEnd, timeEnd);
|
||||
const timeIncrease = `(+${timeChange})`;
|
||||
logger.info('SKIP_FORMAT', ` ${dim(timeIncrease)}`);
|
||||
let timeIncreaseLabel;
|
||||
if (timeEnd - prevTimeEnd > THRESHOLD_SLOW_RENDER_TIME_MS) {
|
||||
timeIncreaseLabel = red(timeIncrease);
|
||||
} else {
|
||||
timeIncreaseLabel = dim(timeIncrease);
|
||||
}
|
||||
logger.info('SKIP_FORMAT', ` ${timeIncreaseLabel}`);
|
||||
prevTimeEnd = timeEnd;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue