Unverified Commit bc15b580 authored by Jimmy Lai's avatar Jimmy Lai Committed by GitHub

misc: fix wrong next start start duration (#56512)

This PR fixes `next start` and `next dev` so that they show the correct server boot-up time. The previous way of computing the start time was incorrect and misleading as it did not start exactly when next started.

Before:
> ✓ Ready in 120ms

After:
> ✓ Ready in 286ms
parent 61122ebc
#!/usr/bin/env node #!/usr/bin/env node
performance.mark('next-start')
import '../server/require-hook' import '../server/require-hook'
import * as log from '../build/output/log' import * as log from '../build/output/log'
import arg from 'next/dist/compiled/arg/index.js' import arg from 'next/dist/compiled/arg/index.js'
......
...@@ -1927,7 +1927,8 @@ export async function copyTracedFiles( ...@@ -1927,7 +1927,8 @@ export async function copyTracedFiles(
serverOutputPath, serverOutputPath,
`${ `${
moduleType moduleType
? `import path from 'path' ? `performance.mark('next-start');
import path from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
import module from 'module' import module from 'module'
const require = module.createRequire(import.meta.url) const require = module.createRequire(import.meta.url)
......
#!/usr/bin/env node #!/usr/bin/env node
import '../server/lib/cpu-profile' import '../server/lib/cpu-profile'
import { startServer } from '../server/lib/start-server' import { startServer } from '../server/lib/start-server'
import { getPort, printAndExit } from '../server/lib/utils' import { getPort, printAndExit } from '../server/lib/utils'
......
if (performance.getEntriesByName('next-start').length === 0) {
performance.mark('next-start')
}
import '../next' import '../next'
import '../node-polyfill-fetch' import '../node-polyfill-fetch'
import '../require-hook' import '../require-hook'
...@@ -130,7 +133,6 @@ export async function startServer({ ...@@ -130,7 +133,6 @@ export async function startServer({
envInfo, envInfo,
expFeatureInfo, expFeatureInfo,
}: StartServerOptions): Promise<void> { }: StartServerOptions): Promise<void> {
const startServerProcessStartTime = Date.now()
let handlersReady = () => {} let handlersReady = () => {}
let handlersError = () => {} let handlersError = () => {}
...@@ -297,11 +299,17 @@ export async function startServer({ ...@@ -297,11 +299,17 @@ export async function startServer({
upgradeHandler = initResult[1] upgradeHandler = initResult[1]
const startServerProcessDuration = const startServerProcessDuration =
Date.now() - startServerProcessStartTime performance.mark('next-start-end') &&
performance.measure(
'next-start-duration',
'next-start',
'next-start-end'
).duration
const formatDurationText = const formatDurationText =
startServerProcessDuration > 2000 startServerProcessDuration > 2000
? `${Math.round(startServerProcessDuration / 100) / 10}s` ? `${Math.round(startServerProcessDuration / 100) / 10}s`
: `${startServerProcessDuration}ms` : `${Math.round(startServerProcessDuration)}ms`
handlersReady() handlersReady()
logStartInfo({ logStartInfo({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment