Skip to content

Commit

Permalink
misc: fix wrong next start start duration (#56512)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
feedthejim committed Oct 6, 2023
1 parent 61122eb commit bc15b58
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/next/src/bin/next.ts
@@ -1,4 +1,5 @@
#!/usr/bin/env node
performance.mark('next-start')
import '../server/require-hook'
import * as log from '../build/output/log'
import arg from 'next/dist/compiled/arg/index.js'
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/build/utils.ts
Expand Up @@ -1927,7 +1927,8 @@ export async function copyTracedFiles(
serverOutputPath,
`${
moduleType
? `import path from 'path'
? `performance.mark('next-start');
import path from 'path'
import { fileURLToPath } from 'url'
import module from 'module'
const require = module.createRequire(import.meta.url)
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/cli/next-start.ts
@@ -1,5 +1,4 @@
#!/usr/bin/env node

import '../server/lib/cpu-profile'
import { startServer } from '../server/lib/start-server'
import { getPort, printAndExit } from '../server/lib/utils'
Expand Down
14 changes: 11 additions & 3 deletions packages/next/src/server/lib/start-server.ts
@@ -1,3 +1,6 @@
if (performance.getEntriesByName('next-start').length === 0) {
performance.mark('next-start')
}
import '../next'
import '../node-polyfill-fetch'
import '../require-hook'
Expand Down Expand Up @@ -130,7 +133,6 @@ export async function startServer({
envInfo,
expFeatureInfo,
}: StartServerOptions): Promise<void> {
const startServerProcessStartTime = Date.now()
let handlersReady = () => {}
let handlersError = () => {}

Expand Down Expand Up @@ -297,11 +299,17 @@ export async function startServer({
upgradeHandler = initResult[1]

const startServerProcessDuration =
Date.now() - startServerProcessStartTime
performance.mark('next-start-end') &&
performance.measure(
'next-start-duration',
'next-start',
'next-start-end'
).duration

const formatDurationText =
startServerProcessDuration > 2000
? `${Math.round(startServerProcessDuration / 100) / 10}s`
: `${startServerProcessDuration}ms`
: `${Math.round(startServerProcessDuration)}ms`

handlersReady()
logStartInfo({
Expand Down

0 comments on commit bc15b58

Please sign in to comment.