Skip to content

Commit 986e392

Browse files
authored
Document Turbopack trace viewer (#78184)
Explains how to run the Turbopack trace viewer. This tool is focused on low-level observability. We use it to optimize Turbopack performance and memory usage. It's also useful for finding slowdowns caused by customization like postcss / custom loaders and such. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
1 parent 6956d5e commit 986e392

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

crates/napi/src/next_api/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub async fn project_new(
382382
thread::spawn(move || {
383383
turbopack_trace_server::start_turbopack_trace_server(trace_file);
384384
});
385-
println!("Turbopack trace server started. View trace at https://turbo-trace-viewer.vercel.app/");
385+
println!("Turbopack trace server started. View trace at https://trace.nextjs.org");
386386
}
387387

388388
subscriber.init();

docs/01-app/03-building-your-application/06-optimizing/14-local-development.mdx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ module.exports = {
7878
}
7979
```
8080

81+
Turbopack automatically analyzes imports and optimizes them. It does not require this configuration.
82+
8183
### 4. Check your Tailwind CSS setup
8284

8385
If you're using Tailwind CSS, make sure it's set up correctly.
@@ -140,15 +142,36 @@ Use this command to see more detailed information about what's happening during
140142
next dev --verbose
141143
```
142144

143-
## Still having problems?
145+
## Turbopack tracing
144146

145-
If you've tried everything and still have issues:
147+
Turbopack tracing is a tool that helps you understand the performance of your application during local development.
148+
It provides detailed information about the time taken for each module to compile and how they are related.
146149

147-
1. Create a simple version of your app that shows the problem.
148-
2. Generate a special file that shows what's happening:
150+
1. Make sure you have the latest version of Next.js installed.
151+
1. Generate a Turbopack trace file:
149152

150153
```bash
151-
NEXT_CPU_PROF=1 npm run dev
154+
NEXT_TURBOPACK_TRACING=1 npm run dev
152155
```
153156

154-
3. Share this file (found in your project's main folder) and the `.next/trace` file on GitHub as a new issue.
157+
1. Navigate around your application or make edits to files to reproduce the problem.
158+
1. Stop the Next.js development server.
159+
1. A file called `trace-turbopack` will be available in the `.next` folder.
160+
1. You can interpret the file using `next internal trace [path-to-file]`:
161+
162+
```bash
163+
next internal trace .next/trace-turbopack
164+
```
165+
166+
On versions where `trace` is not available, the command was named `turbo-trace-server`:
167+
168+
```bash
169+
next internal turbo-trace-server .next/trace-turbopack
170+
```
171+
172+
1. Once the trace server is running you can view the trace at https://trace.nextjs.org/.
173+
1. By default the trace viewer will aggregate timings, in order to see each individual time you can switch from "Aggregated in order" to "Spans in order" at the top right of the viewer.
174+
175+
## Still having problems?
176+
177+
Share the trace file generated in the [Turbopack Tracing](#turbopack-tracing) section and share it on [GitHub Discussions](https://github.com/vercel/next.js/discussions) or [Discord](https://nextjs.org/discord).

packages/next/src/bin/next.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ const internal = program
421421
)
422422

423423
internal
424-
.command('turbo-trace-server')
424+
.command('trace')
425+
.alias('turbo-trace-server')
425426
.argument('[file]', 'Trace file to serve.')
426427
.action((file: string) => {
427428
return import('../cli/internal/turbo-trace-server.js').then((mod) =>

packages/next/src/build/swc/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ function loadNative(importPath?: string) {
12551255
createProject: bindingToApi(customBindings ?? bindings, false),
12561256
startTurbopackTraceServer(traceFilePath) {
12571257
Log.warn(
1258-
'Turbopack trace server started. View trace at https://turbo-trace-viewer.vercel.app/'
1258+
'Turbopack trace server started. View trace at https://trace.nextjs.org'
12591259
)
12601260
;(customBindings ?? bindings).startTurbopackTraceServer(traceFilePath)
12611261
},

0 commit comments

Comments
 (0)