You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add --experimental-cpu-prof flag with worker process profiling
- Add --experimental-cpu-prof to next dev, build, and start commands
- Profiles are saved to .next/cpu-profiles/ on process exit
- Support CPU profiling for worker processes:
- webpack-build workers (server, client, edge-server)
- turbopack-build worker
- static worker
- build-trace worker
- Meaningful profile names for each component (e.g., build-main, build-webpack-server, dev-server)
- Add integration and e2e tests verifying profile name patterns
- Add CLI documentation
|`--debug-prerender`| Debug prerender errors in development. |
89
90
|`--debug-build-paths=<patterns>`| Build only specific routes for debugging. |
91
+
|`--experimental-cpu-prof`| Enables CPU profiling using V8's inspector. Profiles are saved to `.next/cpu-profiles/` on exit. |
90
92
91
93
### `next start` options
92
94
@@ -101,6 +103,7 @@ The following options are available for the `next start` command:
101
103
|`-p` or `--port <port>`| Specify a port number on which to start the application. (default: 3000, env: PORT) |
102
104
|`-H` or `--hostname <hostname>`| Specify a hostname on which to start the application (default: 0.0.0.0). |
103
105
|`--keepAliveTimeout <keepAliveTimeout>`| Specify the maximum amount of milliseconds to wait before closing the inactive connections. |
106
+
|`--experimental-cpu-prof`| Enables CPU profiling using V8's inspector. Profiles are saved to `.next/cpu-profiles/` on exit. |
104
107
105
108
### `next info` options
106
109
@@ -334,6 +337,25 @@ NODE_OPTIONS='-r esm' next
334
337
NODE_OPTIONS='--inspect' next
335
338
```
336
339
340
+
### CPU profiling
341
+
342
+
You can capture CPU profiles to analyze performance bottlenecks in your Next.js application. The `--experimental-cpu-prof` flag enables V8's built-in CPU profiler and saves profiles to `.next/cpu-profiles/` when the process exits:
343
+
344
+
```bash filename="Terminal"
345
+
# Profile the build process
346
+
next build --experimental-cpu-prof
347
+
348
+
# Profile the dev server (profile saved on Ctrl+C or SIGTERM)
349
+
next dev --experimental-cpu-prof
350
+
351
+
# Profile the production server
352
+
next start --experimental-cpu-prof
353
+
```
354
+
355
+
The generated `.cpuprofile` files can be opened in Chrome DevTools (Performance tab → Load profile) or other V8-compatible profiling tools.
356
+
357
+
> **Good to know**: For `next dev`, both the parent process and the child server process are profiled separately, resulting in multiple profile files.
0 commit comments