Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
f1033c39
Commit
f1033c39
authored
Dec 27, 2025
by
Jimmy Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add debug timings
parent
ec25a1de
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
0 deletions
+49
-0
next-dev.ts
packages/next/src/cli/next-dev.ts
+3
-0
router-server.ts
packages/next/src/server/lib/router-server.ts
+34
-0
start-server.ts
packages/next/src/server/lib/start-server.ts
+12
-0
No files found.
packages/next/src/cli/next-dev.ts
View file @
f1033c39
...
...
@@ -319,6 +319,7 @@ const nextDev = async (
nodeOptions
.
inspect
=
formatDebugAddress
(
address
)
}
const
forkStartTime
=
Date
.
now
()
child
=
fork
(
startServerPath
,
{
stdio
:
'inherit'
,
env
:
{
...
...
@@ -330,6 +331,8 @@ const nextDev = async (
NEXT_PRIVATE_TRACE_ID
:
traceId
,
// Pass server options via env to eliminate IPC handshake latency
NEXT_PRIVATE_WORKER_OPTIONS
:
JSON
.
stringify
(
startServerOptions
),
// Pass fork start time for timing measurement
NEXT_PRIVATE_FORK_TIME
:
String
(
forkStartTime
),
NODE_EXTRA_CA_CERTS
:
startServerOptions
.
selfSignedCertificate
?
startServerOptions
.
selfSignedCertificate
.
rootCA
:
defaultEnv
.
NODE_EXTRA_CA_CERTS
,
...
...
packages/next/src/server/lib/router-server.ts
View file @
f1033c39
...
...
@@ -94,16 +94,24 @@ export async function initialize(opts: {
startServerSpan
?:
Span
quiet
?:
boolean
}):
Promise
<
ServerInitResult
>
{
const
timings
:
Record
<
string
,
number
>
=
{}
const
mark
=
(
name
:
string
)
=>
{
timings
[
name
]
=
performance
.
now
()
}
mark
(
'init-start'
)
if
(
!
process
.
env
.
NODE_ENV
)
{
// @ts-ignore not readonly
process
.
env
.
NODE_ENV
=
opts
.
dev
?
'development'
:
'production'
}
mark
(
'before-loadConfig'
)
const
config
=
await
loadConfig
(
opts
.
dev
?
PHASE_DEVELOPMENT_SERVER
:
PHASE_PRODUCTION_SERVER
,
opts
.
dir
,
{
silent
:
false
}
)
mark
(
'after-loadConfig'
)
let
compress
:
ReturnType
<
typeof
setupCompression
>
|
undefined
...
...
@@ -111,12 +119,14 @@ export async function initialize(opts: {
compress
=
setupCompression
()
}
mark
(
'before-fsCheck'
)
const
fsChecker
=
await
setupFsCheck
({
dev
:
opts
.
dev
,
dir
:
opts
.
dir
,
config
,
minimalMode
:
opts
.
minimalMode
,
})
mark
(
'after-fsCheck'
)
const
renderServer
:
LazyRenderServerInstance
=
{}
...
...
@@ -131,6 +141,7 @@ export async function initialize(opts: {
let
originalFetch
=
globalThis
.
fetch
if
(
opts
.
dev
)
{
mark
(
'dev-block-start'
)
const
{
Telemetry
}
=
require
(
'../../telemetry/storage'
)
as
typeof
import
(
'../../telemetry/storage'
)
...
...
@@ -138,11 +149,14 @@ export async function initialize(opts: {
distDir
:
path
.
join
(
opts
.
dir
,
config
.
distDir
),
})
traceGlobals
.
set
(
'telemetry'
,
telemetry
)
mark
(
'after-telemetry'
)
const
{
pagesDir
,
appDir
}
=
findPagesDir
(
opts
.
dir
)
mark
(
'after-findPagesDir'
)
const
{
setupDevBundler
}
=
require
(
'./router-utils/setup-dev-bundler'
)
as
typeof
import
(
'./router-utils/setup-dev-bundler'
)
mark
(
'after-require-setupDevBundler'
)
const
resetFetch
=
()
=>
{
globalThis
.
fetch
=
originalFetch
...
...
@@ -153,6 +167,7 @@ export async function initialize(opts: {
?
opts
.
startServerSpan
.
traceChild
(
'setup-dev-bundler'
)
:
trace
(
'setup-dev-bundler'
)
mark
(
'before-setupDevBundler'
)
const
developmentBundler
=
await
setupDevBundlerSpan
.
traceAsyncFn
(()
=>
setupDevBundler
({
renderServer
,
...
...
@@ -169,6 +184,7 @@ export async function initialize(opts: {
resetFetch
,
})
)
mark
(
'after-setupDevBundler'
)
const
devBundlerService
=
new
DevBundlerService
(
developmentBundler
,
...
...
@@ -182,6 +198,7 @@ export async function initialize(opts: {
service
:
devBundlerService
,
config
:
config
as
NextConfigComplete
,
}
mark
(
'dev-block-end'
)
}
renderServer
.
instance
=
...
...
@@ -886,6 +903,23 @@ export async function initialize(opts: {
}
}
mark
(
'init-end'
)
// Log timing breakdown
if
(
debug
.
enabled
)
{
const
entries
=
Object
.
entries
(
timings
)
const
start
=
timings
[
'init-start'
]
debug
(
'timing breakdown:'
)
for
(
let
i
=
1
;
i
<
entries
.
length
;
i
++
)
{
const
[
prevName
]
=
entries
[
i
-
1
]
const
[
currName
,
currTime
]
=
entries
[
i
]
debug
(
`
${
prevName
}
→
${
currName
}
:
${(
currTime
-
entries
[
i
-
1
][
1
]).
toFixed
(
1
)}
ms`
)
}
debug
(
` TOTAL:
${(
timings
[
'init-end'
]
-
start
).
toFixed
(
1
)}
ms`
)
}
return
{
requestHandler
,
upgradeHandler
,
...
...
packages/next/src/server/lib/start-server.ts
View file @
f1033c39
// Measure fork/spawn overhead - must be at the very top
const
childStartTime
=
Date
.
now
()
const
forkTime
=
process
.
env
.
NEXT_PRIVATE_FORK_TIME
?
childStartTime
-
parseInt
(
process
.
env
.
NEXT_PRIVATE_FORK_TIME
,
10
)
:
null
// Start CPU profile if it wasn't already started.
import
'./cpu-profile'
import
{
getNetworkHost
}
from
'../../lib/get-network-host'
...
...
@@ -40,6 +46,12 @@ import type { ConfiguredExperimentalFeature } from '../config'
const
debug
=
setupDebug
(
'next:start-server'
)
let
startServerSpan
:
Span
|
undefined
// Log fork/spawn timing
const
moduleLoadTime
=
Date
.
now
()
-
childStartTime
if
(
forkTime
!==
null
)
{
debug
(
`fork/spawn overhead:
${
forkTime
}
ms, module load:
${
moduleLoadTime
}
ms`
)
}
/**
* Get the process ID (PID) of the process using the specified port
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment